{"id":24599705,"url":"https://github.com/dobschal/express-route-loader","last_synced_at":"2025-03-18T06:27:55.999Z","repository":{"id":221696382,"uuid":"755133418","full_name":"dobschal/express-route-loader","owner":"dobschal","description":"🪄  Auto load route handlers in Express JS applications.","archived":false,"fork":false,"pushed_at":"2025-03-02T19:22:20.000Z","size":75,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T19:27:36.519Z","etag":null,"topics":["auto-load","autoloader","express","express-js","expressjs","node","node-js","nodejs","router","routes"],"latest_commit_sha":null,"homepage":"https://github.com/dobschal/express-router-loader","language":"JavaScript","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/dobschal.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-02-09T13:45:40.000Z","updated_at":"2025-03-02T19:21:08.000Z","dependencies_parsed_at":"2024-02-09T14:59:17.807Z","dependency_job_id":"b0260604-6c6e-44bf-8cb2-33e6436fa508","html_url":"https://github.com/dobschal/express-route-loader","commit_stats":null,"previous_names":["dobschal/express-router-loader"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dobschal%2Fexpress-route-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dobschal%2Fexpress-route-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dobschal%2Fexpress-route-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dobschal%2Fexpress-route-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dobschal","download_url":"https://codeload.github.com/dobschal/express-route-loader/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244168482,"owners_count":20409535,"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":["auto-load","autoloader","express","express-js","expressjs","node","node-js","nodejs","router","routes"],"created_at":"2025-01-24T13:16:48.263Z","updated_at":"2025-03-18T06:27:55.992Z","avatar_url":"https://github.com/dobschal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Express Route Loader\n\nAutomatically load route handlers from script files, catch errors and map the function name to the URL path.\n\n```javascript\nfunction getArticles() {\n} // becomes HTTP GET /articles 🙌\n```\n\n![Test](https://github.com/dobschal/express-route-loader/actions/workflows/test.yml/badge.svg)\n[![NPM](https://img.shields.io/npm/v/@dobschal/express-route-loader)](https://www.npmjs.com/package/@dobschal/express-route-loader)\n\n## Get Started\n\n### Installation\n\n```bash\n# Install the package via NPM:\nnpm install --save @dobschal/express-route-loader\n```\n\n### Import\n\n```javascript\n// ES6\nimport {routeLoader} from \"@dobschal/express-route-loader\";\n\n// CommonJS\nconst {routeLoader} = require(\"@dobschal/express-route-loader\");\n```\n\n### Use\n\n```javascript\n// Expect to have all route handlers in routes/\napp.use(routeLoader(path.join(__dirname, \"routes\")));\n```\n\n## Router Handler\n\n```javascript\n// Will add GET /users route handler\nexport function getUsers() {\n    // ...\n    return users;\n}\n```\n\n## Example\n\n`app.js`\n\n```javascript\nimport express from \"express\";\nimport path from \"path\";\nimport {routeLoader} from \"@dobschal/express-route-loader\";\n\n// Instantiate express app and configure...\nconst app = express();\n\n// Apply auto loader\napp.use(routeLoader(path.join(__dirname, \"routes\")));\n\napp.listen(/* ... */);\n```\n\n`routes/user.js`\n\n```javascript\n// This will apply as route handler for GET /users\n\nexport async function getUsers(body, req, res) {\n    const users = await loadUsers();\n    res.send({users});\n}\n```\n\n## Auto Response\n\nInstead of calling `res.send(/* ... */)` you can use the return keyword to send a JSON HTTP response.\n\n```typescript\nexport async function getUsers() {\n    return {users: await loadUsers()};\n}\n```\n\n## Error Handling\n\nIf an error is thrown inside a route handler, the error is automatically forwarded to\nthe [Express Error Handler](https://expressjs.com/en/guide/error-handling.html) via the NextFunction.\n\n```javascript\nexport function postLogin({password}) {\n\n    // This will automatically be caught \n    // Just implement a global ExpressJS Error Handler \n    if (passwordIsWrong(password)) {\n        throw new Error(\"Password is wrong.\");\n    }\n}\n```\n\n## Prefixes\n\nYou can add a prefix to each route by exporting a `prefix` string variable.\n\n```javascript\nexport const prefix = \"/api/v1\";\n\nexport function getUsers() { // Will be GET /api/v1/users\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdobschal%2Fexpress-route-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdobschal%2Fexpress-route-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdobschal%2Fexpress-route-loader/lists"}