my-nconf

1.4.3 • Public • Published

Configure your Node.js Applications

NPM   Build Status

Introduction

my-nconf organizes hierarchical configurations for your app deployments.

It lets you define a set of default parameters, and extend them for different deployment environments (development, qa, staging, production, etc.).

Configurations are stored in configuration files within your application, and can be overridden and extended by environment variables

Install:

$ npm i my-nconf -s

Usage:

config.get() will throw an exception for undefined keys to help catch typos and missing values.

Use config.has() to test if a configuration value is defined.

Use configs in your code:

//./app/server.js
import { loadConfig } from 'my-nconf';
 
var config = loadConfig();
var dbConfig = config.get('Customer.dbConfig');
db.connect(dbConfig, ...);
 
if (config.has('optionalFeature.detail')) {
  var detail = config.get('optionalFeature.detail');
  //...
}

By default loadConfig will load in config files found at callsite directory (e.g ./app/) then it will attempt to read and extendDeep appropriate config files found at lookuppaths in order

let lookuppaths = [
     {callsite}/config
    ,{callsite}/.config
    ,{project dir}
    ,{project dir}/config/
    ,{project dir}/.config/
    ,{cwd}
    ,{cwd}/config/
    ,{cwd}/.config/
    ,/Users/{username}/config/
    ,/Users/{username}/.config/
    ,/etc/config
    ,/etc/.config
    ,/config
    ,/.config
    ,confDirs //e.g loadConfig(confDir) loadConfig([confDir1, dir2, dir3], opts)
    ,process.env.NODE_CONFIG_DIR
];

Additionally loadConfig caller's package.name will be appended after each lookuppaths

Start your app server:

export NODE_ENV=production
$ node ./app/server.js

Included parsers:

  • js-yaml
  • properties
  • x2js
  • json5
  • hjson

Package Sidebar

Install

npm i my-nconf

Weekly Downloads

2

Version

1.4.3

License

MIT

Unpacked Size

42.1 kB

Total Files

21

Last publish

Collaborators

  • zen12