-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
ESON JSON Configuration
Douglas Christopher Wilson edited this page Jun 12, 2014
·
7 revisions
The Extended-JSON library allows you to transform JSON using plugins, and comes with several plugins that are very useful for app configuration. To get started add eson:
$ npm install eson --save
Then require eson
and select a configuration file based on the NODE_ENV environment variable, defaulting to "development":
var express = require('express');
var app = express();
var eson = require('eson');
var file = __dirname + '/config/' + app.get('env') + '.json';
The file
variable will then contain a path to ./config/development.json
, ./config/production.json
etcetera. Two plugins are used here, .env()
to read config from environment variables, and .args()
to read from ARGV.
var conf = eson()
.use(eson.env('MYAPP_'))
.use(eson.args())
.read(file);
Now if you had { "log path": "/tmp/app.log" }
in development.json, you could override this with a MYAPP_LOG_PATH=/some/path environment variable, or with node app --log-path /some/path
.