Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

emertechie/bts-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

  1. Command-line arguments
  2. Environment variables
  3. 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 = require('path');
var configDirPath = path.join(__dirname, '../config/');

// Configure and export bts-config
module.exports = require('bts-config')(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 = require('./config'); // Path to your config.js file as described above

var dbName = config.get('dbname);
assert.equals(dbName, 'foo');

// Or:
var dbName = config.getRequired('dbname);  // will throw if `dbName` is falsy

License

MIT

About

Simple yaml based config factory

Resources

License

Stars

Watchers

Forks

Packages

No packages published