Skip to content

Composable app configuration for Node and browser with reading, conversion, validation and type support built-in.

License

Notifications You must be signed in to change notification settings

jakzo/composable-config

Repository files navigation

Composable Config

Composable app configuration with loading, conversion, validation and type support built-in.

Quick Start

npm i composable-config
import { createConfig, buildConfig } from 'composable-config';
import * as ct from 'composable-config/io';
import envLoader from 'composable-config/loaders/env';

const dbConfig = createConfig({
  tableName: ct.string,
});

const serverConfig = createConfig({
  host: {
    _: ct.string,
    default: '127.0.0.1',
  },
  port: {
    _: ct.Port,
    default: 8080,
    env: 'SERVER_PORT',
  },
});

const appConfig = createConfig({
  server: serverConfig,
  db: dbConfig,
});

const config = buildConfig({
  config: appConfig,
  loaders: [envLoader()],
  defaults: {
    db: {
      tableName: 'xyz',
    },
  },
});

assert(process.env['SERVER_PORT']).equals('1234');

assert(config).equals({
  db: {
    tableName: 'xyz',
  },
  server: {
    host: '127.0.0.1',
    port: 1234,
  },
});

About

Composable app configuration for Node and browser with reading, conversion, validation and type support built-in.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published