yaml-env-config

1.1.0 • Public • Published

env-config

A tool for creating a configuration object based on a set of yaml files. Pass env-config the relative path to your configuration, and it will create a tree of options based on yaml files and their names.

This tool also looks for a nested directory with the same name as the current process.env.NODE_ENV, and will deep merge those configuration properties into the base files, so you can explicitly overwrite only the config options that you want on an environment by environment basis.

usage

yaml structure

  ./app
    ./config
      ./production
        app.yaml
      app.yaml
      database.yaml

yaml files

# ./app/config/app.yaml 
 
name: 'My Config'
port: 3000
# ./app/config/database.yaml 
 
driver: mongo
port: 27017
# ./app/config/production/app.yaml 
 
port: 9000

javacript

// Running with NODE_ENV=production
var config = require('env-config')('path/to/config');
 
console.log(config);
/**
 * Yields:
 * {
 *   app: {
 *     name: 'My Config',
 *     port: 9000
 *   },
 *   database: {
 *     driver: 'mongo',
 *     port: 27017
 *   }
 * }
 */

Package Sidebar

Install

npm i yaml-env-config

Weekly Downloads

1

Version

1.1.0

License

ISC

Last publish

Collaborators

  • cdebotton