nestjs-dispatch-module
v0.1.1
Published
Easily configure and lazy load different NestJS modules in different environments.
Maintainers
Readme
Installation
npm install nestjs-dispatch-module --saveUsage
DispatchModule.dispatchFromEnv can be used to lazy load modules based on the value of the environment variable.
import {DispatchModule} from 'nestjs-dispatch-module';
// Dispatch module inclusion based on an environment variable value, and optionally a fallback
@Module({
imports: [DispatchModule.dispatchFromEnv(
'MY_ENV_VAR',
{
production: import('./production').then(m => m.ProductionModule),
staging: import('./staging').then(m => m.StagingModule),
},
{
fallbackModule: () => import('./noop').then(m => m.NoopModule)
}
)]
})
export class AppModule {}
// Or if you prefer to implement your own dispatching logic
@Module({
imports: [DispatchModule.dispatch({
dispatch: (env: NodeJS.ProcessEnv) =>
env['MY_VAR'] === 'production'
? import('./production').then(m => m.ProductionModule)
: import('./noop').then(m => m.NoopModule)
})]
})
export class AppModule {}📜 License
nestjs-dispatch-module is MIT licensed.
