Skip to content

Configuration container for the kings collection.

License

Notifications You must be signed in to change notification settings

kingga/kc-config

Repository files navigation

Kings Collection Configuration Container

Build Status

A configuration container which can load configurations from multiple configuration file types. These include:

  • JSON
  • YAML
  • DotEnv

Installation

Yarn

yarn add @kingga/kc-config

NPM

npm i @kingga/kc-config

Usage

host: localhost
port: 999
user: root
pass: secret
database: db1
import Container from '@kingga/kc-container';
import ConfigServiceProvider, { IConfig } from '@kingga/kc-config';
import { resolve } from 'path';

const container = new Container();
const provider = new ConfigServiceProvider(container);
provider.register();

const config = container.make<IConfig>('IConfig');
config.loadFile(resolve(__dirname, './configs/db.yaml'));

// Some third party library.
db.createConnection({
    host: config.get('db.host', 'localhost'),
    port: config.get('db.port', 3306),
    user: config.get('db.user', 'root'),
    pass: config.get('db.pass', ''),
    database: config.get('db.database'),
});