/node-config

Node.js Application Configuration

Primary LanguageJavaScriptOtherNOASSERTION

Configure your Node.js Applications

Version 1.0 (release notes): Node-config is ready to break out of its pre-1.0 shell since the original release in Oct. 2010. Version 1.0 preview is in the current master branch, and will be published to npm after a short soaking period. Check out the master branch if you'd like a preview prior to the npm release.

NPM   Build Status   release notes

Introduction

Node-config organizes 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.).

This gives your application code a consistent configuration interface, shared among a growing list of npm modules also using node-config.

Project Guidelines

  • Simple - Get started fast
  • Powerful - For multi-node enterprise deployment
  • Flexible - Supporting multiple config file formats
  • Lightweight - Small file and memory footprint
  • Predictable - Well tested foundation for module and app developers

Quick Start

The following examples are in JSON format, but configurations can be in other file formats.

Install in your app directory, and edit the default config file.

$ npm install config
$ mkdir config
$ vi config/default.json

{
  // Customter module configs
  "Customer": {
    "dbConfig": {
      "host": "localhost",
      "port": 5984,
      "dbName": "customers"
    },
    "credit": {
      "initialLimit": 100,
      // Set low for development
      "initialDays": 1
    }
  }
}

Edit config overrides for production deployment:

$ vi config/production.json

{
  "Customer": {
    "dbConfig": {
      "host": "prod-db-server"
    },
    "credit": {
      "initialDays": 30
    }
  }
}

Use configs in your code:

var config = require('config');
...
var dbConfig = config.get('Customer.dbConfig');
db.connect(dbConfig, ...);

Start your app server:

$ export NODE_ENV=production
$ node my-app.js

Running in this configuration, the port and dbName elements of dbConfig will come from the default.json file, and the host element will come from the production.json override file.

Articles

Contributors

lorenwestjosxenyoeheikesnsabovicOsterjour
jberrischnitzan-shakedAlaneorkeiscmccullohabh
DMajrekarjonjonsonjrk-j-kleistGUIbolgovrAskelkana
hisayanEsyaeiriksmjscharlachmmoczulski

License

May be freely distributed under the MIT license.

Copyright (c) 2010-2014 Loren West and other contributors