3.0.0 • Published 8 months ago
nestjs-node-config-module v3.0.0
NestJS Node Config Module
Node Config
Node.js Application Configuration organizes hierarchical configurations for your app deployments.
It lets you define a set of default parameters, and extend them for different deployment environments (development, qa, staging, production, etc.).
Installation
To start using Node Config module, first install the required packages:
$ npm i --save config nestjs-node-config-module
Overview
To use the config module, add ConfigModule
import:
import { ConfigModule } from "nestjs-node-config-module";
@Module({
imports: [ConfigModule.forRoot()],
controllers: [],
providers: [],
})
export class AppModule {
}
Then you can inject config service:
import { ConfigService } from "nestjs-node-config-module";
@Injectable()
export class AppService {
constructor(private configService: ConfigService) {
}
getFoo(): string {
return this.configService.get('foo');
}
}
Options
Config module accepts optional options
parameter, parameters are described below:
ConfigService
You can extend default config service with your one, for example:
import { ConfigService } from "nestjs-node-config-module";
@Injectable()
class MyConfigService extends ConfigService {
getFoo(): string {
return this.get<string>('foo')
}
}
Then you have to register it by passing class to Config Module:
import { ConfigModule } from "nestjs-node-config-module";
@Module({
imports: [ConfigModule.forRoot({
configService: MyConfigService
})],
controllers: [],
providers: [],
})
export class AppModule {
}
And now it's accessible in nest IoC container:
import { MyConfigService } from "./my-config.service";
@Injectable()
export class AppService {
constructor(private configService: MyConfigService) {
}
getFoo(): string {
return this.configService.getFoo();
}
}
NOTE: default ConfigService
is still available and can be injected.