Naboo's Podracing Misadventure
Wondering what’s next for npm?Check out our public roadmap! »


0.0.6 • Public • Published


Config module for node

NPM version Build Status Dependency Status


Via npm:

$ npm install nconfig


var path = require('path');
var options = {
    "path": path.join(__dirname, 'config');
var nconfig = require('nconfig')(options);
var config = nconfig.loadSync('development');


path (string) — Sets the directory path of the configuration files.


nconfig.loadSync(env, [mergeWithEnv])

Loads the configuration file synchronously.


  • env (string) — Environment name. Synonymous to the configuration file's base name.
  • mergeWithEnv (string or array) — If specified, nconfig will load and merge the listed configurations (read below).

Configuration Files

Config files should be in JSON format with a .json extension.


// development.json
    "name": "My App",
    "db": {
        "host": "localhost",
        "user": "root",
        "pass": "abc123"

Loading and Merging Configs

If the mergeWithEnv parameter was specified, nconfig will load and merge config files based on the following rules:

  • The left-most environment's config will have the highest priority while the right-most will have the lowest. Lower priority config properties will be overwritten by config properties of higher priority.
  • Any environment listed to the left of the target environment will be ignored (e.g. ["production", "beta", "testing", "development"] with "beta" as target will not load "production"; "beta" will have the highest priority; "development" will have the lowest priority)
  • Same named properites of type object will have their sub-properties merged.
  • If a string was used in mergeWithEnv, that config will be loaded with lowest priority and will be overwritten by the target environment's config.
  • If the target environment is not an element of the mergeWithEnv array, it will follow the same logic as above with the target environment's config having the highest priority. All of the configs listed in the array will be loaded.
  • Environments with no config files will return { }.


MIT License. Read the LICENSE file.

In summary, you can do whatever you want with the code but if it breaks, sorry :(

How to Contribute

If you find bugs or think some parts can be improved, please post the request on GitHub.

If you want to fix it yourself, kudos! Fork the repo, do your magic, and invoke a pull request. I'll be sure to thank you and add you here as a contributor.


npm i nconfig

DownloadsWeekly Downloads






Last publish


  • avatar