{"id":18862489,"url":"https://github.com/giovannicardamone/express-automatic-routes","last_synced_at":"2025-06-28T13:40:13.843Z","repository":{"id":37097541,"uuid":"287800458","full_name":"GiovanniCardamone/express-automatic-routes","owner":"GiovanniCardamone","description":"fastest way to map directories to URLs in express","archived":false,"fork":false,"pushed_at":"2023-02-23T04:16:29.000Z","size":87,"stargazers_count":18,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-16T12:44:42.434Z","etag":null,"topics":["autoroute","autoroutes","autorouting","express","express-automatic-routes","express-plugin"],"latest_commit_sha":null,"homepage":"https://giovannicardamone.github.io/express-automatic-routes/","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/GiovanniCardamone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"GiovanniCardamone"}},"created_at":"2020-08-15T18:11:57.000Z","updated_at":"2024-06-25T07:26:32.000Z","dependencies_parsed_at":"2023-02-14T16:16:58.448Z","dependency_job_id":null,"html_url":"https://github.com/GiovanniCardamone/express-automatic-routes","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GiovanniCardamone%2Fexpress-automatic-routes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GiovanniCardamone%2Fexpress-automatic-routes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GiovanniCardamone%2Fexpress-automatic-routes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GiovanniCardamone%2Fexpress-automatic-routes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GiovanniCardamone","download_url":"https://codeload.github.com/GiovanniCardamone/express-automatic-routes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223633967,"owners_count":17176870,"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":["autoroute","autoroutes","autorouting","express","express-automatic-routes","express-plugin"],"created_at":"2024-11-08T04:34:39.378Z","updated_at":"2024-11-08T04:34:40.080Z","avatar_url":"https://github.com/GiovanniCardamone.png","language":"JavaScript","funding_links":["https://github.com/sponsors/GiovanniCardamone"],"categories":[],"sub_categories":[],"readme":"# express-automatic-routes\n\n\u003cdiv align=\"center\"\u003e\n\n![Logo](./logo.png)\n\n![JavaScript](https://img.shields.io/badge/ES6-Supported-yellow.svg?style=for-the-badge\u0026logo=JavaScript) \u0026nbsp; ![TypeScript](https://img.shields.io/badge/TypeScript-Supported-blue.svg?style=for-the-badge)\n\n[![NPM version](https://img.shields.io/npm/v/express-automatic-routes.svg?style=flat)](https://www.npmjs.com/package/express-automatic-routes)\n[![NPM downloads](https://img.shields.io/npm/dm/express-automatic-routes.svg?style=flat)](https://www.npmjs.com/package/express-automatic-routes)\n[![Known Vulnerabilities](https://snyk.io/test/github/GiovanniCardamone/express-automatic-routes/badge.svg)](https://snyk.io/test/github/GiovanniCardamone/express-automatic-routes)\n[![GitHub license](https://img.shields.io/github/license/GiovanniCardamone/express-automatic-routes.svg)](https://github.com/GiovanniCardamone/express-automatic-routes/blob/master/LICENSE)\n\n![CI](https://github.com/GiovanniCardamone/express-automatic-routes/workflows/CI/badge.svg?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/GiovanniCardamone/express-automatic-routes/badge.svg?branch=master)](https://coveralls.io/github/GiovanniCardamone/express-automatic-routes?branch=master)\n\n\u003c/div\u003e\n\n\u003e :star: Thanks to everyone who has starred the project, it means a lot!\n\nPlugin to handle routes in express automatically based on directory structure.\n\n## :newspaper: **[Full Documentation](https://giovannicardamone.github.io/express-automatic-routes/)**\n\n[express-automatic-routes](https://giovannicardamone.github.io/express-automatic-routes/)\n\n## :rocket: Install\n\n```sh\nnpm install --save express-automatic-routes\n```\n\n## :blue_book: Usage\n\n### Autoload routes\n\n```js\nimport express from 'express'\nimport autoroutes from 'express-automatic-routes'\n\nconst app = express()\n\nautoroutes(app, {\n  dir: './\u003cautoroutes-directory\u003e' // relative to your cwd\n})\n```\n\n### Create file in autoroutes directory\n\n```js\n//file: `\u003cautoroutes-directory\u003e/some/route.js`\n//url:  `http://your-host/some/route`\n\nexport default (expressApp) =\u003e ({\n  get: (request, response) =\u003e {\n    response.status(200).send('Hello, Route').end()\n  }\n})\n```\n\n### Using typescript support for module\n\n```typescript\n//file: `\u003cautoroutes-directory\u003e/some/route.ts`\n//url:  `http://your-host/some/route`\n\nimport { Application, Request, Response } from 'express'\nimport { Resource } from 'express-automatic-routes'\n\nexport default (express: Application) =\u003e \u003cResource\u003e {\n  get: (request: Request, response: Response) =\u003e {\n    response.status(200).send('Hello, Route!').end()\n  }\n}\n```\n\n### Accepts params in autoroutes\n\n\u003e :information_source: file/directory name must follow syntax `:paramName` or `{paramName}`\n\n```js\n//file: `\u003cautoroutes-directory\u003e/users/{userId}/photos.js`\n//mapped to: `\u003cyour host\u003e/users/:userId/photos`\n\nexport default (expressApp) =\u003e ({\n  get: (request, response) =\u003e {\n      response.end(`photos of user ${request.params.userId}`)\n  }\n})\n```\n\n## :arrow_forward: Module definition\n\neach file must export a function that accept express as parameter, and return an object with the following properties:\n\n```javascript\nexport default (expressApp) =\u003e ({\n  middleware: [ /* your middlewares */ ]\n  delete: { /* your handler logic */},\n  get: { /* your handler logic */  },\n  head: { /* your handler logic */  },\n  patch: { /* your handler logic */  },\n  post: { /* your handler logic */  },\n  put: { /* your handler logic */  },\n  options: { /* your handler logic */  },\n})\n```\n\n## :arrow_forward: Middleware module definition\n\nthe `middleware` parameter can be one of the following:\n\n- `undefined` _(just omit it)_\n- `Middleware function` _(a function complain to [express middleware](https://expressjs.com/en/guide/using-middleware.html) definition)_\n- `An Array of Middleware functions`\n\nexample:\n\n\u003e :information_source: simple middleware\n\n```javascript\nexport default (expressApp) =\u003e ({\n  middleware: (req, res, next) =\u003e next()\n  /* ... */\n})\n```\n\n\u003e :information_source: array of middleware\n\n```javascript\nconst m1 = (req, res, next) =\u003e next()\nconst m2 = (req, res, next) =\u003e next()\n\nexport default (expressApp) =\u003e ({\n  middleware: [m1, m2]\n  /* ... */\n})\n```\n\n## :arrow_forward: Route definition\n\nA route can be a function (likes middleware but without `next` parameter) or an object who has the following properties:\n\n- middleware // same as module middleware\n- handler // the handler of the function\n\nexamples:\n\n\u003e :information_source: simple route method\n\n```javascript\nexport default (expressApp) =\u003e ({\n  get: (req, res) =\u003e res.send('Hello There!')\n})\n```\n\n\u003e :information_source: route method with middleware(s)\n\n```javascript\nexport default (expressApp) =\u003e ({\n  get: {\n    middleware: (req, res, next) =\u003e next()\n    handler: (req, res) =\u003e res.send('Hello There!')\n  }\n})\n```\n\n## :arrow_forward: Skipping files\n\nto skip file in routes directory, prepend the `.` or `_` charater to filename\n\nexamples:\n\n```text\nroutes\n├── .ignored-directory\n├── _ignored-directory\n├── .ignored-js-file.js\n├── _ignored-js-file.js\n├── .ignored-ts-file.ts\n├── _ignored-ts-file.ts\n├── ignored-js-test.test.js\n└── ignored-ts-test.test.ts\n```\n\n\u003e :warning: also any `*.test.js` and `*.test.ts` are skipped!\n\nthis is useful if you want to have a lib file containts functions that don't have to be a route, so just create the file with `_` prepending character\n\n## :page_facing_up: License\n\nLicensed under [MIT](./LICENSE)\n\n## :sparkles: Contributors\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"http://giovannicardamone.github.io\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/5117748?v=4?s=100\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eGiovanni Cardamone\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/GiovanniCardamone/express-automatic-routes/commits?author=GiovanniCardamone\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/GiovanniCardamone/express-automatic-routes/commits?author=GiovanniCardamone\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#example-GiovanniCardamone\" title=\"Examples\"\u003e💡\u003c/a\u003e \u003ca href=\"#maintenance-GiovanniCardamone\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.\n\nContributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiovannicardamone%2Fexpress-automatic-routes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgiovannicardamone%2Fexpress-automatic-routes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiovannicardamone%2Fexpress-automatic-routes/lists"}