bts-config
Simple yaml based config factory
Install
npm install bts-config
Overview
App configuration factory based on nconf and using js-yaml for yaml file support.
Uses nconf's hierarchical abilities to load configuration values in the order:
- Command-line arguments
- Environment variables
- One or more yaml files (as passed to configuration function defined below)
Configuration
require('bts-config')
returns a configuration function which takes the following args:
function(pathToConfigDir, configFileName1, configFileName2, ...)
Each config file name can use one or more "{ENV_VAR_NAME}" templates which get replaced with the corresponding environment variable values.
Define a config.js
file in your application project as follows:
// Configure path to your config file directory. E.g:var path = ;var configDirPath = path; // Configure and export bts-configmoduleexports = configDirPath 'app-{NODE_ENV}.yml' 'db-{NODE_ENV}.yml';
So, if the NODE_ENV
environment variable is prod
, this will use ../config/app-prod.yml
and ../config/db-prod.yml
files to populate the configuration store.
Usage
Assuming you've configured a config.js
file in your own project as defined above, and have a yaml file as follows:
dbname: foo
then the usage looks like:
var config = ; // Path to your config.js file as described above var dbName = config; // will throw if `dbName` is falsy
License
MIT