0.2.1 • Published 2 years ago

@rapidcode/app v0.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@rapidcode/app

this library is a wrapper on express() for creating the express app and attach express routes with the app.

Usage

This module exposes 3 methods, the createApp, the registerRoute and the registerMultipleRoutes.

Creating the app

const { createApp } = require("@rapidcode/app");
const app = createApp(); // this is the express app object

var usersRouter = require("./routes/users"); // must be a express.Router() object
app.use("/users", usersRouter);

app.listen("8000", () => {
  console.log("Running on http://localhost:8000");
});

Registering a route with the app

const { createApp, registerRoute } = require("@rapidcode/app");
const app = createApp(); // this is the express app object
var usersRouter = require("./routes/users"); // must be a express.Router() object

registerRoute(app, "/users", usersRouter); // attach the route with the app

app.listen("8000", () => {
  console.log("Running on http://localhost:8000");
});

Registering multiple routes

const { createApp, registerMultipleRoutes } = require("@rapidcode/app");
const app = createApp(); // this is the express app object
var usersRouter = require("./routes/users"); // must be a express.Router() object
var productsRouter = require("./routes/products"); // must be a express.Router() object

registerMultipleRoutes(app, [
  { path: "/users", router: usersRouter },
  { path: "/products", router: productsRouter },
]);

app.listen("8000", () => {
  console.log("Running on http://localhost:8000");
});

PS:

You can create the routes using express.Router(), or using the @rapidcode/route.

0.2.1

2 years ago

0.2.0

2 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago