{"id":23240494,"url":"https://github.com/node-ecosystem/universal-autorouter","last_synced_at":"2026-02-13T14:23:35.166Z","repository":{"id":268271511,"uuid":"903832253","full_name":"node-ecosystem/universal-autorouter","owner":"node-ecosystem","description":"Universal filesystem autoloader for routes","archived":false,"fork":false,"pushed_at":"2025-01-29T00:40:36.000Z","size":1292,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-25T06:20:42.851Z","etag":null,"topics":["api","api-rest","autoloader","bun","express-js","expressjs","filesystem","hono","nodejs","routes","vike","vite","web-server"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/node-ecosystem.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-15T17:09:44.000Z","updated_at":"2025-02-12T13:18:34.000Z","dependencies_parsed_at":"2025-01-03T21:35:33.448Z","dependency_job_id":null,"html_url":"https://github.com/node-ecosystem/universal-autorouter","commit_stats":null,"previous_names":["node-ecosystem/universal-autoloader","node-ecosystem/universal-autorouter"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-ecosystem%2Funiversal-autorouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-ecosystem%2Funiversal-autorouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-ecosystem%2Funiversal-autorouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-ecosystem%2Funiversal-autorouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-ecosystem","download_url":"https://codeload.github.com/node-ecosystem/universal-autorouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242117658,"owners_count":20074436,"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":["api","api-rest","autoloader","bun","express-js","expressjs","filesystem","hono","nodejs","routes","vike","vite","web-server"],"created_at":"2024-12-19T05:12:26.174Z","updated_at":"2026-02-13T14:23:35.128Z","avatar_url":"https://github.com/node-ecosystem.png","language":"TypeScript","readme":"# universal-autorouter\n\nAn universal plugin that scans the file system and automatically loads to a server all routes in a target directory.\n\nInspired by [elysia-autoload](https://github.com/kravetsone/elysia-autoload) package and compatible with [Node.js](https://nodejs.org) and [Bun](https://bun.sh) runtimes.\n\n## ⚙️ Install\n\n```sh\nyarn add universal-autorouter\n```\n\n## 📖 Usage\n\n### Register the Plugin (example with [Hono](https://hono.dev))\n\n```ts\n// /app.ts\nimport path from 'node:path'\nimport { serve } from '@hono/node-server'\nimport { Hono } from 'hono'\nimport autoloadRoutes from 'universal-autorouter'\n\nconst app = new Hono()\n\nawait autoloadRoutes(app, {\n  // Pattern to scan route files\n  pattern: '**/*.ts',\n  // Prefix to add to routes\n  prefix: '/api',\n  // Source directory of route files: use \"relative\" path\n  routesDir: path.resolve(import.meta.dirname, 'api')\n})\n\nconst port = +(process.env.PORT || 3000)\n\nserve({\n  fetch: app.fetch,\n  port\n}, () =\u003e console.log(`Server running at http://localhost:${port}`))\n```\n\n### Create a Route\n\n```ts\n// /routes/index.ts\nimport type { Context } from 'hono'\n\nexport default (c: Context) =\u003e {\n  return c.text('Hello World!')\n}\n```\n\n### Directory Structure\n\nGuide on how `universal-autorouter` matches routes:\n\n```\n├── app.ts\n├── routes\n│   ├── index.ts         // index routes\n│   ├── posts\n│   │   ├── index.ts\n│   │   └── [id].ts      // dynamic params\n│   ├── likes\n│   │   └── [...].ts     // wildcard\n│   ├── domains\n│   │   ├── @[...]       // wildcard with @ prefix\n│   │   │   └── index.ts\n│   ├── frontend\n│   │   └── index.tsx    // usage of tsx extension\n│   ├── events\n│   │   ├── (post).ts    // dynamic method\n│   │   └── (get).ts\n│   └── users.ts\n└── package.json\n```\n\n- `/routes/index.ts` → GET `/`\n- `/routes/posts/index.ts` → GET `/posts`\n- `/routes/posts/[id].ts` → GET `/posts/:id`\n- `/routes/users.ts` → GET `/users`\n- `/routes/likes/[...].ts` → GET `/likes/*`\n- `/routes/domains/@[...]/index.ts` → GET `/domains/@*`\n- `/routes/frontend/index.tsx` → GET `/frontend`\n- `/routes/events/(post).ts` → POST `/events`\n- `/routes/events/(get).ts` → GET `/events`\n\n### Options\n\n| Key               | Type            | Default                        | Description                                                                      |\n| ----------------- | --------------- | ------------------------------ | -------------------------------------------------------------------------------- |\n| pattern?          | string          | `**/*.{ts,tsx,js,jsx,mjs,cjs}` | [Glob patterns](https://en.wikipedia.org/wiki/Glob_(programming))                |\n| prefix?           | string          | ` `                            | Prefix to be added to each route                                                 |\n| routesDir?        | string          | `./api`                        | The folder where routes are located (use a *relative* path)                      |\n| defaultMethod?    | Method | string | `get`                          | Default method to use when the route filename doesn't use the (\u003cMETHOD\u003e) pattern |\n| viteDevServer?    | ViteDevServer   | _undefined_                    | Developer server instance of [Vite](https://vite.dev) to use SSR module loader   |\n| skipNoRoutes?     | boolean         | `false`                        | Skip the throw error when no routes are found                                    |\n| skipImportErrors? | boolean         | `false`                        | Skip the import errors with the `default export` of a rotue file                 |\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-ecosystem%2Funiversal-autorouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-ecosystem%2Funiversal-autorouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-ecosystem%2Funiversal-autorouter/lists"}