@rapidcode/app
v0.2.1
Published
Create an Express App
Downloads
1
Readme
@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
.