@seanmcgary/config-composer

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

Usage no npm install needed!

<script type="module">
  import seanmcgaryConfigComposer from 'https://cdn.skypack.dev/@seanmcgary/config-composer';
</script>

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
    });
}