{"id":15527350,"url":"https://github.com/fjodor-rybakov/nestjs-dynamic-providers","last_synced_at":"2025-09-07T02:05:10.297Z","repository":{"id":43477585,"uuid":"425992026","full_name":"fjodor-rybakov/nestjs-dynamic-providers","owner":"fjodor-rybakov","description":"💉 Inject providers into module by glob pattern","archived":false,"fork":false,"pushed_at":"2025-06-13T08:12:14.000Z","size":915,"stargazers_count":16,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-31T19:43:49.455Z","etag":null,"topics":["decorator","dynamic","glob","inject","module","nest","nestjs","pattern","providers","typescript"],"latest_commit_sha":null,"homepage":"","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/fjodor-rybakov.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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-11-08T20:59:41.000Z","updated_at":"2025-01-22T13:50:13.000Z","dependencies_parsed_at":"2023-12-29T15:28:03.319Z","dependency_job_id":"5789154d-65fd-4291-825d-984998debcf1","html_url":"https://github.com/fjodor-rybakov/nestjs-dynamic-providers","commit_stats":{"total_commits":65,"total_committers":4,"mean_commits":16.25,"dds":0.523076923076923,"last_synced_commit":"7b663edb1c4af120f1070396b0f1a70e0b232a79"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fjodor-rybakov/nestjs-dynamic-providers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjodor-rybakov%2Fnestjs-dynamic-providers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjodor-rybakov%2Fnestjs-dynamic-providers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjodor-rybakov%2Fnestjs-dynamic-providers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjodor-rybakov%2Fnestjs-dynamic-providers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fjodor-rybakov","download_url":"https://codeload.github.com/fjodor-rybakov/nestjs-dynamic-providers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fjodor-rybakov%2Fnestjs-dynamic-providers/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273986629,"owners_count":25202708,"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","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["decorator","dynamic","glob","inject","module","nest","nestjs","pattern","providers","typescript"],"created_at":"2024-10-02T11:05:41.770Z","updated_at":"2025-09-07T02:05:10.266Z","avatar_url":"https://github.com/fjodor-rybakov.png","language":"TypeScript","funding_links":["https://paypal.com/paypalme/fjodorrybakov"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"blank\"\u003e\u003cimg src=\"https://nestjs.com/img/logo_text.svg\" width=\"320\" alt=\"Nest Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master\n[travis-url]: https://travis-ci.org/nestjs/nest\n[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux\n[linux-url]: https://travis-ci.org/nestjs/nest\n\n  \u003cp align=\"center\"\u003eA progressive \u003ca href=\"http://nodejs.org\" target=\"blank\"\u003eNode.js\u003c/a\u003e framework for building efficient and scalable server-side applications, heavily inspired by \u003ca href=\"https://angular.io\" target=\"blank\"\u003eAngular\u003c/a\u003e.\u003c/p\u003e\n    \u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/fjodor-rybakov/discord-nestjs/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/@nestjs/core.svg\" alt=\"Package License\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://paypal.com/paypalme/fjodorrybakov\"\u003e\u003cimg src=\"https://img.shields.io/badge/Donate-PayPal-dc3d53.svg\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## 🧾 Description\n\nDo you have many classes of the same type and adding each of them to the module is burdensome?\nThis package was created in order to be able to add providers to the module using the glob pattern.\n\n## 👨🏻‍💻 Installation \u003ca name=\"Installation\"\u003e\u003c/a\u003e\n\n```bash\n$ npm install nestjs-dynamic-providers\n```\n\nOr via yarn\n\n```bash\n$ yarn add nestjs-dynamic-providers\n```\n\n## ▶️ Usage \u003ca name=\"Usage\"\u003e\u003c/a\u003e\n\n\u003e You may notice that files with `.ts` extension have a glob pattern is set for `.js`. This example assumes that you are\n\u003e compiling files from `typescript` to `javascript`. This note does not apply for `ts-node`.\n\n\u003e ⚠️**Important! Files are searched from the startup root(`process.cwd()`) by default. \n\u003e To override this, you can pass startup path in `resolveDynamicProviders('my/startup/folder')` as argument.**\n\nFirst you need to call the initialization function in bootstrap.\n\n```typescript\n/* main.ts */\n\nimport { AppModule } from './app.module';\nimport { NestFactory } from '@nestjs/core';\nimport { resolveDynamicProviders } from 'nestjs-dynamic-providers';\n\nasync function bootstrap() {\n  await resolveDynamicProviders();\n  const app = await NestFactory.createApplicationContext(AppModule);\n  await app.init();\n}\n\nbootstrap();\n```\n\nThen just add `@InjectDynamicProviders` decorator to the module. The sample below will add to the providers of the module\nall classes that it finds in files that end in `.animal.js`.\n\n\u003e By default, classes are searched for that are marked with `@Injectable()` decorator.\n\u003e To override you need to pass `filterPredicate` as parameters to `@InjectDynamicProviders()`.\n\n- `@InjectDynamicProviders` decorator takes list of glob patterns or list of options as parameters.\n\n```typescript\n/* animal.module.ts */\n\nimport { Module } from '@nestjs/common';\nimport { InjectDynamicProviders } from 'nestjs-dynamic-providers';\nimport { AnyOtherProvider } from './any-other-provider';\n\n@InjectDynamicProviders('dist/**/*.animal.js')\n@Module({\n  providers: [AnyOtherProvider], // Will be [AnyOtherProvider, Hippo, Lion]\n})\nexport class AnimalModule {}\n```\n\n```typescript\n/* hippo.animal.ts */\n\nimport { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class Hippo {}\n```\n\n```typescript\n/* lion.animal.ts */\n\nimport { Injectable } from '@nestjs/common';\n\n@Injectable()\nexport class Lion {}\n```\n\n```typescript\n/* app.module.ts */\n\nimport { Module } from '@nestjs/common';\nimport { AnimalModule } from './animal.module';\n\n@Module({\n  imports: [AnimalModule],\n})\nexport class AppModule {}\n```\n\nYou can also add providers to exports.\n\n```typescript\n/* animal.module.ts */\n\nimport { Module } from '@nestjs/common';\nimport { InjectDynamicProviders } from 'nestjs-dynamic-providers';\nimport { AnyOtherProvider } from './any-other-provider';\n\n@InjectDynamicProviders({ pattern: 'dist/**/*.animal.js', exportProviders: true })\n@Module({\n  providers: [AnyOtherProvider], // Will be [AnyOtherProvider, Hippo, Lion]\n  exports: [AnyOtherProvider], // Will be [AnyOtherProvider, Hippo, Lion]\n})\nexport class AnimalModule {}\n```\n\nTo override the search criteria for `class` in file, use `filterPredicart`.\n\n```typescript\n/* bot.module.ts */\n\nimport { Module } from '@nestjs/common';\nimport { InjectDynamicProviders, IsObject } from 'nestjs-dynamic-providers';\n\n@InjectDynamicProviders({\n  pattern: '**/*.command.js',\n  filterPredicate: (type) =\u003e // Filter only object type and class has decorator with metadata key `ANY_METADATA_KEY`\n    IsObject(type) \u0026\u0026 Reflect.hasMetadata('ANY_METADATA_KEY', type.prototype),\n})\n@Module({})\nexport class BotModule {}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffjodor-rybakov%2Fnestjs-dynamic-providers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffjodor-rybakov%2Fnestjs-dynamic-providers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffjodor-rybakov%2Fnestjs-dynamic-providers/lists"}