configury
Easy management of environment based configuration
Installation
npm install configury
Usage
configury([path, defaultSection])
Using in-memory configuration
var configury = config =
Using configuration file on disk
var configury = config =
Using default config section other than 'global'
var configury = config =
config.raw()
var configury = config = config//-> { "global": { "foo": "bar" }, "development": { "foo": "bar" } ... }
config.write([path, cb])
Save the current configuration in memory to disk
var configury = config = // Write to './properties.json' file on disk synchronouslyconfig // Write to './properties.json' file on disk asynchronouslyconfig // Write to './myBackupProperties.json' file on disk asynchronouslyconfig // Write to './myBackupProperties.json' file on disk synchronouslyconfig
config.set(key, value)
Setting a variable in 'global' configuration
var configury = config = configconfig//-> { "global": { "Alice": "Bob" } ... }
Setting a variable in 'myCustomGlobal'
var configury = config = configconfig//-> { "myCustomGlobal": { "Alice": "Bob" } ... }
config.section(section)
var configury = config = var mySection = config//-> mySection = { set: function(key, value), merge: function(object) }
Setting a variable in 'mySection'
var configury = config = mySection = config mySectionconfig//-> { "global": { ... } "mySection" { "Alice": "Bob" } }
config.merge()
Merging an object over a property in the configuration
var configury = config = config//-> { "global": { "foo": "bar" } ... }config//-> { "global": { "foo": "woo" }, "pickles": "bananas" }
Merging an object over a property in 'mySection'
var configury = config = mySection = config mySection//-> { "global": { ... } "mySection": { "foo": "bar" } }mySection//-> { "global": { ... } "mySection": { "foo": "woo" } }
Substitution
By default, configury will substitute any values that match the pattern: %string%
. This will substitute the current value with the value of that key if it exists. E.g:
var configury = config = configconfig console//-> 'http://localhost:3000/login'
Credits
Paul Serby follow me on twitter @serby
Licence
Licensed under the New BSD License