Simple library for configuring Node.js apps
JavaScript Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE.txt
README.md
lint.json
package.json
run-coverage.sh
run-lint.sh

README.md

Build Status

nor-config -- Config library for Node.js

Warning! This code is experimental and in a state of preliminary development. Use at your own risk.

License

It's under MIT-style open source license -- see LICENSE.txt.

Installation

You can install it simply from NPM:

npm install nor-config

Usage

App defaults can be configured in file ./config.json (or later in the source code with ._def()):

{
  "port": 8080
}

Local settings (overrides values in ./config.js) for the app can be set in ./local/config.json:

{
  "host": '192.168.1.1',
  "port": 3000
}

The ./app.js uses it like this:

var config = require('nor-config').from(__dirname);
config._def('host', 'localhost');   // Set default value
config._require('port');            // If port is missing, throws an exception.
console.log(config.host + ':' + config.port);

The output will be 192.168.1.1:3000.

The library will also read package.json if it exists, and saves contents from it to config.pkg.