{"id":16623343,"url":"https://github.com/notunderctrl/express-router-handler","last_synced_at":"2025-10-29T22:31:39.288Z","repository":{"id":65126531,"uuid":"582439766","full_name":"notunderctrl/express-router-handler","owner":"notunderctrl","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-03T11:04:22.000Z","size":23,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T05:31:35.427Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/notunderctrl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-26T20:56:56.000Z","updated_at":"2023-10-23T21:18:53.000Z","dependencies_parsed_at":"2023-02-01T05:50:12.474Z","dependency_job_id":null,"html_url":"https://github.com/notunderctrl/express-router-handler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notunderctrl%2Fexpress-router-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notunderctrl%2Fexpress-router-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notunderctrl%2Fexpress-router-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/notunderctrl%2Fexpress-router-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/notunderctrl","download_url":"https://codeload.github.com/notunderctrl/express-router-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238909399,"owners_count":19550839,"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":[],"created_at":"2024-10-12T03:23:21.859Z","updated_at":"2025-10-29T22:31:33.992Z","avatar_url":"https://github.com/notunderctrl.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Express Router Handler\n\nAn Express js routes handler that will automatically generate API routes for you based on the folder structure.\n\n### Folder structure example (as nested as you want it!):\n\n![](https://i.imgur.com/z98NjrW.png)\n\n### `RouterHandler` options:\n\n`app` - your express server instance.\n\n`routesPath` - the path to your routes folder - Use the `path` library to define this.\n\n`prefix` - this changes your API routing. For example: By default your requests could look something like this:\n\n- `http://localhost:3000/users`\n\nAdding a `prefix` like `/api` will change the routing to look like this:\n\n- `http://localhost:3000/api/users`\n\nIMPORTANT: Adding a trailing slash to `prefix` will affect your routing.\n\n### CommonJS Example:\n\n```js\nconst path = require('path');\nconst express = require('express');\nconst RouterHandler = require('express-router-handler').default;\n\nconst app = express();\nconst PORT = 3000;\n\nRouterHandler({\n  app,\n  // IMPORTANT: Use the path library to define routesPath\n  routesPath: path.join(__dirname, 'routes'),\n  // prefix: '/api', // optional\n});\n\napp.listen(PORT, () =\u003e {\n  console.log(`Server running on port ${PORT}`);\n});\n```\n\n### Typescript Example:\n\n```js\nimport express, { Application } from 'express';\nimport RouterHandler from 'express-router-handler';\nimport path from 'path';\n\nconst app: Application = express();\nconst PORT = 3000;\n\nRouterHandler({\n  app,\n  // IMPORTANT: Use the path library to define routesPath\n  routesPath: path.join(__dirname, 'routes'),\n  // prefix: '/api', // optional\n});\n\napp.listen(PORT, () =\u003e {\n  console.log(`Server running on port ${PORT}`);\n});\n```\n\nYour route file needs to export a function\n\n### CommonJS example:\n\n`/routes/users/:id/get.js`\n\n```js\nmodule.exports = (req, res) =\u003e {\n  const id = req.params.id;\n  res.send(`User id: ${id}`);\n};\n```\n\n### TypeScript example:\n\n`/routes/users/:id/get.js`\n\n```js\nimport { Request, Response } from 'express';\n\nexport default (req: Request, res: Response) =\u003e {\n  const id = req.params.id;\n  res.send(`User id: ${id}`);\n};\n```\n\n## Known issues\n\n- The library only works in CommonJS projects due to the nature of import/exports.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotunderctrl%2Fexpress-router-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotunderctrl%2Fexpress-router-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotunderctrl%2Fexpress-router-handler/lists"}