Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 780 Bytes

README.md

File metadata and controls

34 lines (27 loc) · 780 Bytes

NodeJS application configuration files loader

  • NodeJS, Typescript
  • Config chaining (hierarchy)
  • Multiple environments support, local overwrites
  • JSON/JS configs, JS is to use environment variables
  • Validation using class-validator library
  • Configs are typed

Usage

Load config:

    const configSource = new ConfigFileChain(
      path.resolve(__dirname, '../config'),
      process.env.PROJECT_ENV as string,
    );
    const configFactory = new ConfigFactory(configSource);

    const serverConfig = await configFactory.create<ServerConfig>(ServerConfig);

Create your own config type:

export class ExampleConfig extends Config {
  @IsNotEmpty()
  public value!: string;

  public getName(): string {
    return 'example';
  }
}