{"id":23127622,"url":"https://github.com/hlfshell/express-walker","last_synced_at":"2025-09-01T13:33:17.884Z","repository":{"id":33137972,"uuid":"36777617","full_name":"hlfshell/express-walker","owner":"hlfshell","description":"A router loader for node and express apps.","archived":false,"fork":false,"pushed_at":"2015-12-22T16:27:59.000Z","size":10,"stargazers_count":42,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-29T02:43:12.943Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/hlfshell.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}},"created_at":"2015-06-03T03:25:44.000Z","updated_at":"2023-11-09T00:02:17.000Z","dependencies_parsed_at":"2022-08-31T09:42:02.508Z","dependency_job_id":null,"html_url":"https://github.com/hlfshell/express-walker","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/hlfshell%2Fexpress-walker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlfshell%2Fexpress-walker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlfshell%2Fexpress-walker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hlfshell%2Fexpress-walker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hlfshell","download_url":"https://codeload.github.com/hlfshell/express-walker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230091585,"owners_count":18171528,"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-12-17T09:14:15.779Z","updated_at":"2024-12-17T09:14:16.288Z","avatar_url":"https://github.com/hlfshell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Express Walker\nThis is a helper module to allow easily loading express routers for APIs. Routes are determined by the directory structure and filenames you use. Also, it allows the passing of parameters in any fashion you wish to each router as its loaded, allowing the easy passing of models and other variables throughout your project. \n\n## Installation\n```sh\nnpm install express-walker\n```\n\n## Example\n\n### Your index.js\n```js\nvar app = require('express')();\nvar walker = new (require('express-walker'))(\n    {\n      directory: './api/v0.1/',\n      app: app,\n      root: '/api/'\n    }\n  )\n  .pass(app, models, yetAnotherArgument)\n  .load()\n  .then(function(){\n    //All routers have been loaded into the express app now.\n    app.listen(3000);\n  });\n```\n\n### Your directory structure:\n\n```\n|\n|--api\n|----v0.1\n|------admin\n|--------users.js\n|--------sales.js\n|------register.js\n|------doStuff.js\n```\n\n### Your typical router\n_doStuff.js_\n```js\nvar express = require('express');\n\nmodule.exports = function(app, models, yetAnotherArgument){\n\n  var doStuffRouter = express.Router();\n  \n  doStuffRouter.route('/')\n    .get(function(req, res){\n      console.log(\"Hello World!\");\n    });\n\n  return doStuffRouter\n};\n```\n_Note the return_\n\n### And, finally, your resulting API paths:\n\n```no-highlight\n  /api/admin/users\n  /api/admin/sales\n  /api/register/\n  /api/doStuff/\n```\n\n## Documentation\n\n### Setup\n\n```js\nvar walker = new (require('express-walker'))();\nwalker\n  .directory('./targetDir')\n  .root('targetAPIRoot')\n  .app(app)\n  .pass(list, of, arguments, to, pass)\n  .load()\n  .then(function(){\n    app.listen(3000);\n  });\n  \n//OR\n\nvar walker = new (require('express-walker'))(\n    {\n      app: app,\n      directory: './targetDir',\n      root: 'targetAPIRoot',\n      args: [list, of, arguments, to, pass] \n    }\n  )\n  .load(function(){\n    app.listen(3000);\n  });\n```\n\n### Parameters\n\n#### Directory\nThe directory you wish to walk through. All sub-directories are also traversed.\n\n#### Root\nThe root of the API to be added as ap refix to each router when its added. If a router had an endpoint of '/test/something' A root of '/' would not add anything as a prefix - the resulting route would be '/test/something'. A root of '/api/' would result in an endpoint of '/api/test/something'.\n\n#### app\nThe express app you've created - it's used to add each router to the app.\n\n#### args\nOptional. When added in the constructor, it's an array of values or variables. when using the .pass() method, it's called with as many arguments as you wish (without the array). You can have as many or as little as you wish.\n\nThese arguments are passed, in the same order, to each router on require-time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlfshell%2Fexpress-walker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhlfshell%2Fexpress-walker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlfshell%2Fexpress-walker/lists"}