Socket
Book a DemoInstallSign in
Socket

trafico

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trafico

The most awesome router for Express.

latest
Source
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

Tráfico

npm version Downloads Build Status Coverage Status codebeat badge Greenkeeper badge

🚥 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 = require('express');
const Trafico = require('trafico');

const app = express();
const trafico = new Trafico({
  express,
  routes: `/path/to/routes`,
  controllers: `/path/to/controllers`
});

app.use(trafico.route());
app.listen(port, () => {
  console.log(`Up on port: ${port}`);
});

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.exports = (router, controller) => {
  router.get('/', controller.index);
  router.get('/date', controller.date);

  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:

module.exports = {
  index: (req, res) => {
    res.send({ hello: 'world' });
  },
  
  date: (req, res) => {
    res.send({ date: +new Date() });
  }
};

Working examples

Have a look at the /test folder. ExpressBoilerplate also uses Tráfico.

Contribute

fork https://github.com/aichholzer/trafico

License

MIT

Keywords

express

FAQs

Package last updated on 16 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts