setConfig
A Configuration Loader for Node.js
(C) Pradeep Mishra pradeep23oct@gmail.com
Load configuration for node.js application on enviroment basis.
setConfig follows some convention to simplify config loading and handling.
Features
- Simple to use
- Supports commenting in configuration json file
- Helper functions to handle configuration
Example usage
setConfig use default.json for loading default configuration and {enviroment}.json for loading environment specifc configuration.
/myApp/configs/default.json
// default config "db": "host": "localhost" "port": 1234 "name": "users" "rateLimit": "limit": 100 // comment is also supported in config json files "flag" : false
/myApp/configs/development.json
// dev config "rateLimit": "limit": 1000 // comment is also supported in config json files
var setConfig = ; // instantiate setConfigvar config = ; /*SetConfig support environment variable to set application's enviroment and configuration directory path. NODE_ENV=developmentNODE_CONFIG_DIR=/myApp/configs/ ORYou can set it programatically */var configDir = __dirname + '/config';config;config; // call load method to load all configurations config; // now setConfig is ready to use // get propertyconfig; // get internal config properties with periodconfig; // set propertyconfig; // remove propertyconfig; // check property existconfig; // get current environmentconfig; // returns JSON representation of current configurationconfig;
npm install setconfig --save