{"id":20498249,"url":"https://github.com/thenoim/fastify-loader","last_synced_at":"2025-04-13T18:41:39.557Z","repository":{"id":38272651,"uuid":"148041228","full_name":"TheNoim/fastify-loader","owner":"TheNoim","description":"The route loader for the cool kids!","archived":false,"fork":false,"pushed_at":"2023-01-06T01:43:26.000Z","size":1517,"stargazers_count":17,"open_issues_count":20,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-12T16:47:59.176Z","etag":null,"topics":["fastify","fastify-plugin","hacktoberfest","loader","routes"],"latest_commit_sha":null,"homepage":"","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/TheNoim.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}},"created_at":"2018-09-09T15:55:48.000Z","updated_at":"2022-07-08T16:40:52.000Z","dependencies_parsed_at":"2023-02-05T02:00:19.969Z","dependency_job_id":null,"html_url":"https://github.com/TheNoim/fastify-loader","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/TheNoim%2Ffastify-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNoim%2Ffastify-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNoim%2Ffastify-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheNoim%2Ffastify-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheNoim","download_url":"https://codeload.github.com/TheNoim/fastify-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248764376,"owners_count":21158074,"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":["fastify","fastify-plugin","hacktoberfest","loader","routes"],"created_at":"2024-11-15T18:13:34.331Z","updated_at":"2025-04-13T18:41:39.537Z","avatar_url":"https://github.com/TheNoim.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-loader\n\n_The route loader for the cool kids!_\n\n[![NpmLicense](https://img.shields.io/npm/l/fastify-loader.svg?style=for-the-badge)](https://www.npmjs.com/package/fastify-loader)\n[![David](https://img.shields.io/david/TheNoim/fastify-loader.svg?style=for-the-badge)](https://github.com/TheNoim/fastify-loader)\n[![GitHub package version](https://img.shields.io/github/package-json/v/TheNoim/fastify-loader.svg?style=for-the-badge)](https://github.com/TheNoim/fastify-loader)\n[![NPM Link](https://img.shields.io/badge/npm-fastify--loader-red.svg?style=for-the-badge)](https://www.npmjs.com/package/fastify-loader) [![Greenkeeper badge](https://badges.greenkeeper.io/TheNoim/fastify-loader.svg)](https://greenkeeper.io/)\n\nDo you also want an easy way to load routes for fastify? YEAH me too! This is why I made this module.\n\n`fastify-loader` makes it easy to load routes from a directory.\n\n#### Features\n\n- Looks cool\n- No need to `module.export = (fastify) =\u003e { /* your code here */ }` \n- No need to export the fastify instance itself\n- No `module.export = { path: '/api/test', handler: (req, reply) =\u003e {} }`\n\n#### Please, give me an example!\n\n```javascript\n// File: ./api/hello.js\n\n// YES, really! You don't need to require anything here. \n// The fastify instance gets injected in any file matched by the glob.\nfastify.get('/api/hello', async () =\u003e {\n    // Complex code here\n    return { hello: true };\n})\n```\n\n```javascript\n// File: ./server.js\n\nconst fastify = require('fastify')();\n\n// Just register the plugin and add glob array which files to loud\nfastify.register(require('fastify-loader'), {\n    paths: ['./api/**/*.js'], // A glob array\n    name: \"fastify\" // [Optional] if you want to do something like this: YOURNAMEHERE.get('/api/test')\n});\n\nfastify.listen(1337, err =\u003e {\n    if (err) console.trace(err);\n    console.log('http://127.0.0.1:1337');\n});\n```\n\n#### Installation\n\nLike any other npm module.\n\n```bash\nyarn add fastify-loader\n# or with npm\nnpm i fastify-loader --save\n```\n\n#### How does this work?\n\nIt uses [vm2](https://github.com/patriksimek/vm2) to inject the fastify instance and other vars into the scope of each file.\n\n#### WebStorm/{INSERT OTHER IDE HERE} says that fastify is an unknown variable. What can I do?\n\nIf your IDE supports [JSDoc](http://usejsdoc.org/), you can append this to the file.\n\n```diff\n// File: ./api/hello.js\n+ /**\n+  * @var {fastify.FastifyInstance} fastify\n+  */\n\n// noinspection ES6ModulesDependencies\nfastify.get('/api/hello', async () =\u003e {\n    // Complex code here\n    return { hello: true };\n})\n```\n\nOr better if your IDE supports typescript typings, because then you can do this:\n\n```typescript\n// File: ./api/hello.js\n+ /// \u003creference types=\"fastify\"/\u003e\n+ /// \u003creference types=\"fastify-loader\"/\u003e\n\n// noinspection ES6ModulesDependencies\nfastify.get('/api/hello', async () =\u003e {\n    // Complex code here\n    return { hello: true };\n})\n```\n\n#### Do tests exist?\n\nYes. You can run `yarn test` or `npm run test` after you installed the dependencies.\n\n#### Inject more than just fastify\n\n```javascript\nfastify.register(require('fastify-loader'), {\n    paths: ['./api/**/*.js'], // A glob array\n    inject: {\n        pi: 3.14 // pi is now available as var in each js file in ./api\n    }\n});\n```\n\n#### License\n\nThe MIT License (MIT)\n\nCopyright (c) 2018 Nils Bergmann\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenoim%2Ffastify-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthenoim%2Ffastify-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthenoim%2Ffastify-loader/lists"}