-
-
Notifications
You must be signed in to change notification settings - Fork 17.4k
ESON JSON Configuration
visionmedia edited this page Oct 10, 2012
·
6 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 eson = require('eson');
var env = process.env.NODE_ENV || 'development';
var file = __dirname + '/config/' + 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
.