settings-lib
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -5,3 +5,3 @@ { | ||
"main" : "./lib/settings.js", | ||
"version" : "0.0.1", | ||
"version" : "0.0.2", | ||
"author" : "Joshua Thomas (http://github.com/brozeph)", | ||
@@ -19,11 +19,11 @@ "engines": { | ||
"dependencies": { | ||
"async": "~0.2.9" | ||
"async": "~0.2.10" | ||
}, | ||
"devDependencies": { | ||
"chai": "~1.7.2", | ||
"coveralls": "~2.0.16", | ||
"jscoverage": "~0.3.8", | ||
"jshint": "~2.1.10", | ||
"mocha": "~1.12.1", | ||
"mocha-lcov-reporter": "0.0.1" | ||
"chai": "*", | ||
"coveralls": "*", | ||
"jscoverage": "*", | ||
"jshint": "*", | ||
"mocha": "*", | ||
"mocha-lcov-reporter": "*" | ||
}, | ||
@@ -34,4 +34,4 @@ "scripts": { | ||
"test": "mocha --check-leaks -R spec -r ./test/common.js -u bdd ./test/lib", | ||
"posttest": "NODE_SETTINGSLIB_COVERAGE=true mocha -R mocha-lcov-reporter -r ./test/common.js -u bdd ./test/lib | ./node_modules/coveralls/bin/coveralls.js" | ||
"posttest_DISABLE": "NODE_SETTINGSLIB_COVERAGE=true mocha -R mocha-lcov-reporter -r ./test/common.js -u bdd ./test/lib | ./node_modules/coveralls/bin/coveralls.js" | ||
} | ||
} |
@@ -5,4 +5,10 @@ # Settings Library | ||
This module allows an application to specify a base configuration file that contains settings necessary for development. Subsequent configuration file overrides can be applied to override configuration settings in the base config, either via NODE_ENV, other environment variables, via command line switches or all of the above. | ||
A base configuration file can be specified that contains settings necessary for development. Subsequent configuration can be applied to augment and override configuration settings in the base config, either via NODE_ENV, other environment variables, via command line switches or all of the above! | ||
This module is useful in that it allows you to abstract configuration management from your application and deployment at runtime, thus enabling you to avoid checking in sensitive configuration values (i.e. usernames, passwords, secret keys, etc.) to source control. | ||
[![Build Status](https://secure.travis-ci.org/brozeph/settings-lib.png)](http://travis-ci.org/brozeph/settings-lib) | ||
[![Dependency Status](https://gemnasium.com/brozeph/settings-lib.png)](https://gemnasium.com/brozeph/settings-lib) | ||
[![Coverage Status](https://coveralls.io/repos/brozeph/settings-lib/badge.png)](https://coveralls.io/r/brozeph/settings-lib) | ||
## Installation | ||
@@ -19,3 +25,3 @@ | ||
settings = require('settings'), | ||
options = {}; | ||
options = { baseConfigPath : './config/config.json' }; | ||
@@ -71,2 +77,48 @@ settings.initialize(options, function (err, config) { | ||
In the event that you wish to override specific configuration keys directly via an environment variable, simply specify and environment variable mapping in the options when initializing the module: | ||
```Javascript | ||
var | ||
settings = require('settings'), | ||
options = { | ||
readEnvironmentMap : { | ||
APP_HOSTNAME : 'server.hostname' | ||
} | ||
}; | ||
settings.initialize(options, function (err, config) { | ||
// work with config | ||
console.log('hostname: %s', config.server.hostname); | ||
}); | ||
``` | ||
When executing your node application, simply supply the configured environment variable: | ||
```Bash | ||
APP_HOSTNAME=myapp.mydomain.com node app.js | ||
``` | ||
### Read Command Line Mapping | ||
Similar to environment variable configuration key mapping, command line configuration key mapping is possible as well. Specify a command line key mapping in the options when initializing the module: | ||
```Javascript | ||
var | ||
settings = require('settings'), | ||
options = { | ||
readCommandLineMap : { | ||
'--hostname' : 'server.hostname' | ||
} | ||
}; | ||
settings.initialize(options, function (err, config) { | ||
// work with config | ||
console.log('hostname: %s', config.server.hostname); | ||
}); | ||
``` | ||
When executing your node application, simply supply the configured environment variable: | ||
```Bash | ||
node app.js --hostname myapp.mydomain.com | ||
``` |
@@ -327,2 +327,24 @@ describe('settings', function () { | ||
}); | ||
it('should create config for environment mappings when base config key does not exist', function (done) { | ||
defaultOptions.readEnvironmentMap = { | ||
'APP_NO_KEY' : 'no-key.sub-no-key', | ||
}; | ||
process.env.APP_NO_KEY = 'created from environment variable'; | ||
settingsLib.initialize( | ||
defaultOptions, | ||
function (err, settings) { | ||
should.not.exist(err); | ||
should.exist(settings['no-key']); | ||
should.exist(settings['no-key']['sub-no-key']); | ||
settings['no-key']['sub-no-key'] | ||
.should.equal('created from environment variable'); | ||
delete process.env.APP_NO_KEY; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -407,3 +429,26 @@ | ||
}); | ||
it('should create config for command line switches when base config key does not exist', function (done) { | ||
defaultOptions.readCommandLineMap = { | ||
'--no-key' : 'no-key.sub-no-key', | ||
}; | ||
process.argv.push('--no-key'); | ||
process.argv.push('created from command line switch'); | ||
settingsLib.initialize( | ||
defaultOptions, | ||
function (err, settings) { | ||
should.not.exist(err); | ||
should.exist(settings['no-key']); | ||
should.exist(settings['no-key']['sub-no-key']); | ||
settings['no-key']['sub-no-key'] | ||
.should.equal('created from command line switch'); | ||
process.argv = process.argv.slice(0, process.argv.length - 2); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29205
13
724
122
Updatedasync@~0.2.10