An npm package config parser.
If you use Node.js you already know that
npm is awesome, but I am really sure that you mostly use it only
npm install your dependencies. Turns out that
npm has way more power than that, like creating new modules, bundling them, publishing them and it even allows you to start up your apps, set configuration options on your
package.json and even overwrite your default settins using
Install the module with:
npm install npcp
// without npcphttp;// with npcpvar config = ;http;
The usage of
npcp is really straight forward. First, you'll need to add a
config field on your
package.json, then, you'll need to create a
start (or similar) setting on the same
package.json in order to let npm inject the
npm_package_config_* variables on
process.env, and finally just assign the module to your favorite variable name and use it.
"name": "test""description": "a cool test of npcp""version": "0.1.0""scripts":"tryme": "node tryme.js""dependencies":"npcp": "0.1.0""config":"port": 3000"connections":"host": "localhost:3001""host": "localhost:3002"
console;console;console;console;console;var config = ;console;console;configconnections;
And, when running the above examples using npm...
$ npm run-script tryme> firstname.lastname@example.org tryme> node tryme.jsWithout npcp... :-(process.env.npm_package_config_port 3000process.env.npm_package_config_connections_0_host localhost:3001process.env.npm_package_config_connections_1_host localhost:3002---With npcp... :-Dconfig.port 3000config.connections localhost:3001config.connections localhost:3002
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
Copyright (c) 2013 Erick Ruiz de Chavez Licensed under the MIT license.