Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/byndyusoft/nest-dynamic-module
DynamicModule helper for NestJS
https://github.com/byndyusoft/nest-dynamic-module
modules nestjs nodejs
Last synced: 12 days ago
JSON representation
DynamicModule helper for NestJS
- Host: GitHub
- URL: https://github.com/byndyusoft/nest-dynamic-module
- Owner: Byndyusoft
- License: apache-2.0
- Created: 2021-08-17T05:13:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T08:51:39.000Z (about 1 year ago)
- Last Synced: 2024-12-17T23:17:21.463Z (25 days ago)
- Topics: modules, nestjs, nodejs
- Language: TypeScript
- Homepage:
- Size: 204 KB
- Stars: 3
- Watchers: 11
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nest-dynamic-module
[![npm@latest](https://img.shields.io/npm/v/@byndyusoft/nest-dynamic-module/latest.svg)](https://www.npmjs.com/package/@byndyusoft/nest-dynamic-module)
[![test workflow](https://github.com/Byndyusoft/nest-dynamic-module/actions/workflows/test.yaml/badge.svg?branch=master)](https://github.com/Byndyusoft/nest-dynamic-module/actions/workflows/test.yaml)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)DynamicModule helper for NestJS
## Requirements
- Node.js v12 LTS or later
- npm or yarn## Install
```bash
npm install @byndyusoft/nest-dynamic-module
```or
```bash
yarn add @byndyusoft/nest-dynamic-module
```## Usage
Example usage:
```typescript
import {
DynamicModuleHelper,
TRegisterAsyncOptions,
} from "@byndyusoft/nest-dynamic-module";
import { DynamicModule, Inject, Injectable, Module } from "@nestjs/common";class ExampleOptionsDto {
public readonly connectionString!: string;
}const EXAMPLE_OPTIONS_TOKEN = Symbol("EXAMPLE_OPTIONS_TOKEN");
@Injectable()
class ExampleProvider {
public constructor(
@Inject(EXAMPLE_OPTIONS_TOKEN)
options: ExampleOptionsDto,
) {
console.log(options.connectionString);
}
}@Module({})
class ExampleModule {
public static registerAsync(
options?: TRegisterAsyncOptions,
): DynamicModule {
return DynamicModuleHelper.registerAsync(
{
module: ExampleModule,
global: true,
providers: [ExampleProvider],
exports: [ExampleProvider],
},
EXAMPLE_OPTIONS_TOKEN,
options,
);
}
}class ConfigDto {
public readonly exampleOptions!: ExampleOptionsDto;
}@Module({
imports: [
ExampleModule.registerAsync({
inject: [ConfigDto],
useFactory: (config: ConfigDto) => config.exampleOptions,
}),
],
})
class AppModule {}
```## Maintainers
- [@Byndyusoft/owners](https://github.com/orgs/Byndyusoft/teams/owners) <>
- [@Byndyusoft/team](https://github.com/orgs/Byndyusoft/teams/team)## License
This repository is released under version 2.0 of the
[Apache License](https://www.apache.org/licenses/LICENSE-2.0).