Application configuration on #nodejs with #convict

Oscar Brito


I'm definitively trying Convict to solve some configurations issues like:

  • Most applications will have at least a few different deployment environments, each with their own configuration needs.  
  • Including credentials and sensitive information in source can be problematic. 
  •  Debug / Release configurations 



Configuration example:



var convict = require('convict');

// define a schema
var conf = convict({
env: {
doc: "The applicaton environment.",
format: ["production", "development", "test"],
default: "development",
env: "NODEENV"
},
ip: {
doc: "The IP address to bind.",
format: "ipaddress",
default: "127.0.0.1",
env: "IP
ADDRESS",
},
port: {
doc: "The port to bind.",
format: "port",
default: 0,
env: "PORT"
}
});


// load environment dependent configuration
var env = conf.get('env');
conf.loadFile('./config/' + env + '.json');

// perform validation
conf.validate();

module.exports = conf;


Node.js facade:



var conf = require('./config.js');



LINK:
https://github.com/lloyd/node-convict



Visit www.divhide.com for more informations, contacts and news about Web Development.
See other blog posts at blog.divhide.com.



Divhide purpose is to follow the HTML5 movement and contribute with applications which prove the quality of technology.


Feel free to contact divhide.