Easy deployment configuration
With configist you get the possibility to configure your application in various ways (in precedence order):
config
inpackage.json
config:{environment}
inpackage.json
- environment variables
- command line arguments
- custom objects
Let's say the configuration is like this:
// package.json "config": "listen": "127.0.0.1:5000" "config:development": "db": "mongodb://localhost" "config:production": "listen": "0.0.0.0:80" "db": "mongodb://db1.example.net:2500"
Basic usage:
var config = ; console;
Output when NODE_ENV=development (or not given):
{ listen: '127.0.0.1:5000',
db: 'mongodb://localhost',
env: 'development' }
Output when NODE_ENV=production:
{ listen: '0.0.0.0:80',
db: 'mongodb://db1.example.net:2500',
env: 'production' }
You can change the configuration dynamically. The commands are all equivalent and sets the listen
parameter:
node . --listen=:3000npm start --listen=:3000LISTEN=:3000 node .LISTEN=:3000 npm start
You can load multiple configurations:
var configist = ; configist;configist;configist;configist; console;
Happy hacking!
By the way, you can install it:
npm install configist