🚥 Awesome -zero dependency- router for Express.
Tráfico
will map routes to controllers and enable them in your Express application, so you don't have to do it manually and for each one. This provides an easier abstraction and enables a drop-in-and-use route/controller setup.
Basic use
const express = ;const Trafico = ; const app = ;const trafico = express routes: `/path/to/routes` controllers: `/path/to/controllers`; app;app;
Routes
In your routes
folder (/path/to/routes
) create the routes you need to be mapped to your application. For example:
| path/to/routes
| home.js
| user.js
The home.js
route would look similar to this (define your routes as you normally would in your Express application):
module { router; router; return router;};
Controllers
Tráfico
will load all routes from the routes path
you specify and try to look for the controllers to match them. Create your controllers in the controllers
folder (/path/to/controllers
). Controllers must be named like their corresponding routes.
| path/to/controllers
| home.js
| user.js
The home.js
controller would expose the methods mapped in the route:
moduleexports = { res; } { res; };
Working examples
Have a look at the /test
folder. ExpressBoilerplate also uses Tráfico
.
Contribute
fork https://github.com/aichholzer/trafico