Nancy's Preferred Machete

    validatable-config-provider
    TypeScript icon, indicating that this package has built-in type declarations

    0.5.0 • Public • Published

    Class-based validatable config provider for NodeJS

    npm version

    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

    See base provider tests

    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

    Install

    npm i validatable-config-provider

    DownloadsWeekly Downloads

    1

    Version

    0.5.0

    License

    MIT

    Unpacked Size

    29.9 kB

    Total Files

    46

    Last publish

    Collaborators

    • hardcorepoet