![Known Vulnerabilities](https://snyk.io/test/github/gms1/HomeOfThings/badge.svg)
![License](https://img.shields.io/npm/l/@homeofthings/nestjs-config.svg?style=flat-square)
HomeOfThings - Config for NestJs
a configuration module for NestJS providing a ConfigurationService
based on node-config
installation
npm install @homeofthings/nestjs-config
quick start
import module in AppModule
by providing options synchronously
@Module({
imports: [
ConfigModule.forRoot(ConfigModule, {}),
],
})
export class AppModule {}
import module in AppModule
by providing options asynchronously
@Module({
imports: [
ConfigModule.forRootAsync(ConfigModule, {
imports: [],
useFactory: (): Promise<ConfigModuleOptions> =>
Promise.resolve({
}),
inject: [],
}),
],
})
export class AppModule {}
using for bootstrapping
const configService = ConfigModule.createConfigService({});
...
bootstrap();
NOTE: if you decide to combine this method with the imports into AppModule
from above, only the options given to the first method will be taken into account
read configuration values
using one of the methods provided by the ConfigService
:
export declare class ConfigService {
readonly configDirectory: string;
readonly environment: string;
constructor(_opts: ConfigModuleOptions);
getConfig(key: string): object | undefined;
reloadConfig(): void;
getString(key: string, defaultValue: string): string;
getNumber(key: string, defaultValue: number): number;
getBoolean(key: string, defaultValue: boolean): boolean;
getObject(key: string, defaultValue: object): object;
getPath(key: string, defaultValue: string): string;
getOptionalString(key: string): string | undefined;
getOptionalNumber(key: string): number | undefined;
getOptionalBoolean(key: string): boolean | undefined;
getOptionalObject(key: string): object | undefined;
getOptionalPath(key: string): string | undefined;
}
reload configuration on SIGHUP
process.on('SIGHUP', () => ConfigService.getInstance().reloadConfig());
RELEASE NOTES
CHANGELOG