Concon is a command line tool for Node.js that helps you take control your configurations.
Installation:
Install Concon globally:
sudo npm install -g concon
Initialize your module and add a configuration variable:
sudo npm init
sudo concon add port 80 hello world
Install Concon locally
sudo npm install concon
Use the Concon module in your app:
varhttp=require('http');varconcon=require('concon');concon(function(error,config){if(error)throwerr;varserver=http.createServer(function(request,response){response.writeHead(200);response.write(config.hello);response.end();});server.listen(config.port,function(error){if(!error)console.log('\nListening on port: '+config.port);});});
Documentation (Command Line):
Warning: Concon will only work if you've already made a package.json.
Warning: By default if no other command is recognized, Concon assumes that you are trying to update key/value pairs. It's likely your main intent, and this makes things faster.
add:
Adds one or more key/value pairs to the config in your package.json.
sudo concon port 80
sudo concon add port 80
sudo concon add port 80 hello world
update:
Updates one or more key/value pairs.
sudo concon port 3000
sudo concon update port 3000
sudo concon update port 80 hello world
rm/remove:
Removes one or more keys.
sudo concon rm port
sudo concon rm port hello
sudo concon remove port
ls/list:
Lists the current configuration in the package.json.
concon ls
concon list
Documentation (The Module):
Options:
- Required Keys (Optional):
An Array of keys that are critical to the callback's operation. If one of these keys is missing, Concon pass back an error into the callback.
- Callback:
This function gets two arguments back (error, config). If there is an error, you should probably just throw it. But, it's your choice.
Example:
varhttp=require('http');varconcon=require('concon');//get the config object, required keys are 'port' and 'hello'.concon(['port','hello'],function(error,config){if(error)throwerr;//create server that passes back the value of key 'hello'.varserver=http.createServer(function(request,response){response.writeHead(200);response.write(config.hello);response.end();});//have the server listen on the value of key 'port'server.listen(config.port,function(error){if(!error)console.log('\nListening on port: '+config.port);});});