Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@seanmcgary/config-provider

smcgary1ISC1.0.0TypeScript support: included

A node module that allows you to build a hierarchical config structure that can source values from the environment.

readme

config-provider

A node module that allows you to build a hierarchical config structure that can source values from the environment.

Install

yarn add @seanmcgary/config-provider

# or

npm install --save @seanmcgary/config-provider

Usage

mkdir -p src/config
// src/config/index.ts
import { ConfigProvider } from '@seanmcgary/config-provider';

import server, { ServerConfigShape } from './server';

export interface ConfigShape {
    server: ServerConfigShape;
}

const provider = new ConfigProvider<ConfigShape>({
    environmentPrefix: 'MY_SUPER_COOL_APP'
});

provider.addConfig<ServerConfigShape>(server, 'server');

const config = provider.getConfig();
export default config;
// src/config/server.ts
import { Config, ExtractValueFn } from '@seanmcgary/config-provider';

export interface ServerConfigShape {
    port: number;
}

export default (ExtractValue: ExtractValueFn): Config<ServerConfigShape> => {
    return new Config<ServerConfigShape>({
        port: ExtractValue({
            name: 'port',
            value: 9000
        }).int
    });
}