routers-api
With an Node-Express server usually you have to require all your routes and mount them. That's fine for a few routes, but for large applications this can get heavy.
This module is supposed to make this task a little bit easyer by loading all files within a given folder (defaults to ./routes) and mounting them as routes relatively to the ./routes folder.
For example:
application |-> bin |-> public |-> routes |-> index.js |-> users.js |-> admin |-> index.js |-> dashboard.js |-> customers.js
This folder structure would generate the following routes:
//users/admin/admin/dashboard/admin/customers
Notice that index.js files are translated to root slashes /.
So, the only thing that this module is expecting is a Router (express.Router()) instance to work.
// routes/users.jsconst Router = // your routes goes here moduleexports = Router;
This piece of code wraps the whole thing toggether. The following example is a common "resourcefull" route declaration.
// routes/users.jsconst Router = Router; moduleexports = Router;
The above example would generate something like this:
GET /usersGET /users/:idPOST /usersPATCH /users/:idDELETE /users/:id
Installation & Usage
npm install routers-api --save
// app.jsconst express = ;const app = ; // middlewares goes hereapp;// ... // require the module and pass the// express instanceapp; // if you don't use the default routes folder// you can specify the path to your own// as the second argumentapp './path/to/routes'; moduleexports = app;