validatable-config-provider
v0.5.0
Published
NodeJS class-based application configuration provider
Downloads
51
Maintainers
Readme
Class-based validatable config provider for NodeJS
Usage
- Create configuration structure in your config directory (see node-config)
- Create class for your configuration section (database config, auth config etc.) and mark fields you want to validate with decorators (see class-validator)
- Get your configuration using instance of ValidatableConfigProvider
Example
import { IsNumber, IsString } from 'class-validator';
import { ValidatableConfigProviderBuilder } from 'validatable-config-provider';
export class DatabaseConfig {
@IsString()
host: string;
@IsNumber()
port: number;
}
const provider = ValidatableConfigProviderBuilder.getInstance();
const dbConfig = provider.getSection<DatabaseConfig>(DatabaseConfig, 'db');
console.log(dbConfig.port);
Module for NestJS is also bundled with this package