{"id":17235278,"url":"https://github.com/aichholzer/trafico","last_synced_at":"2025-04-06T08:16:06.887Z","repository":{"id":57378795,"uuid":"110787735","full_name":"aichholzer/trafico","owner":"aichholzer","description":"🚥 Awesome -zero dependency- router for Express.","archived":false,"fork":false,"pushed_at":"2020-05-23T11:44:39.000Z","size":211,"stargazers_count":1,"open_issues_count":13,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T10:11:43.628Z","etag":null,"topics":["express","rest","rest-api","router","routing","traffic"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aichholzer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-15T05:27:40.000Z","updated_at":"2019-07-16T02:24:38.000Z","dependencies_parsed_at":"2022-09-26T16:41:32.873Z","dependency_job_id":null,"html_url":"https://github.com/aichholzer/trafico","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichholzer%2Ftrafico","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichholzer%2Ftrafico/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichholzer%2Ftrafico/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aichholzer%2Ftrafico/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aichholzer","download_url":"https://codeload.github.com/aichholzer/trafico/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247451666,"owners_count":20940944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","rest","rest-api","router","routing","traffic"],"created_at":"2024-10-15T05:32:48.685Z","updated_at":"2025-04-06T08:16:06.872Z","avatar_url":"https://github.com/aichholzer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/aichholzer/trafico/master/assets/cover.png\" alt=\"Tráfico\" /\u003e\n\u003c/p\u003e\n\n[![npm version](https://badge.fury.io/js/trafico.svg)](https://badge.fury.io/js/trafico)\n[![Downloads](https://img.shields.io/npm/dt/trafico.svg)](https://www.npmjs.com/package/trafico)\n[![Build Status](https://travis-ci.org/aichholzer/trafico.svg?branch=master)](https://travis-ci.org/aichholzer/trafico)\n[![Coverage Status](https://coveralls.io/repos/github/aichholzer/trafico/badge.svg?branch=master)](https://coveralls.io/github/aichholzer/trafico?branch=master)\n[![codebeat badge](https://codebeat.co/badges/05bcb301-f614-4c2c-892a-557253770e85)](https://codebeat.co/projects/github-com-aichholzer-trafico-master)\n[![Greenkeeper badge](https://badges.greenkeeper.io/aichholzer/trafico.svg)](https://greenkeeper.io/)\n\n##### 🚥 Awesome -zero dependency- router for Express.\n\n\n`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.\n\n\n### Basic use\n\n```js\nconst express = require('express');\nconst Trafico = require('trafico');\n\nconst app = express();\nconst trafico = new Trafico({\n  express,\n  routes: `/path/to/routes`,\n  controllers: `/path/to/controllers`\n});\n\napp.use(trafico.route());\napp.listen(port, () =\u003e {\n  console.log(`Up on port: ${port}`);\n});\n```\n\n\n### Routes\n\nIn your `routes` folder (`/path/to/routes`) create the routes you need to be mapped to your application. For example:\n\n```\n| path/to/routes\n  | home.js\n  | user.js\n```\n\nThe `home.js` route would look similar to this (define your routes as you normally would in your Express application):\n\n```js\nmodule.exports = (router, controller) =\u003e {\n  router.get('/', controller.index);\n  router.get('/date', controller.date);\n\n  return router;\n};\n```\n\n\n### Controllers\n\n`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.\n\n```\n| path/to/controllers\n  | home.js\n  | user.js\n```\n\nThe `home.js` controller would expose the methods mapped in the route:\n\n```js\nmodule.exports = {\n  index: (req, res) =\u003e {\n    res.send({ hello: 'world' });\n  },\n  \n  date: (req, res) =\u003e {\n    res.send({ date: +new Date() });\n  }\n};\n```\n\n\n### Working examples\n\nHave a look at the `/test` folder. [ExpressBoilerplate](https://github.com/aichholzer/ExpressBoilerplate) also uses `Tráfico`.\n\n\n### Contribute\n```\nfork https://github.com/aichholzer/trafico\n```\n\n\n### License\n\n[MIT](https://github.com/aichholzer/trafico/blob/master/LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faichholzer%2Ftrafico","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faichholzer%2Ftrafico","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faichholzer%2Ftrafico/lists"}