service-cloud-config is a nodejs module that provides client-side support for externalized configuration in a distributed system.
currently only supports: Consul
$ npm install service-cloud-config
service-cloud-configr used the service name to discovery the settings
- service - Module name. Default null
- adapter - Used adpter. Default null
- store - save service config local. Default true
- mergeWithConfigEnv - If this option is enabled then the module settings will inherit the module envServiceName. Default true
- envServiceName - The parent module name: Default environment
If mergeWithConfigEnv = true then
example:
environment config = {
database:{
ip:"127.0.0.1",
port:8091
},
elasticsearch:{
ip:"127.0.0.1",
port:9200
}
}
my-module config = {
elasticsearch:{
ip:"192.168.99.100",
port:9202
},
amqp:{
host:"127.0.0.1"
}
}
result config = {
database:{
ip:"127.0.0.1",
port:8091
},
elasticsearch:{
ip:"192.168.99.100",
port:9202
},
amqp:{
host:"127.0.0.1"
}
}
- start(callback) - start adpater connection
- getData(options, callback) - get all configurations remotely
- get(key) - get config value locally. Only works if store = true
- getRemoteValue(key, callback) - get single config key remotely
Note:
- The consul adapter uses kv to store configurations
adapter:{
name:'consul',
connection:{
host: '192.168.99.100',
port: 8500
}
},
Consul kv
my-service/database/ip
var ServiceCloudConfig = require('service-cloud-config');
var config = new ServiceCloudConfig({
service:'my-service',
adapter:{
name:'consul',
connection:{
host: '192.168.99.100',
port: 8500
}
},
mergeWithConfigEnv:true
});
config.start( function(err, data){
config.getData(function(err, data){
console.log(data);
});
});
-
get configurations (locally)
- take paths in documents which can include nested paths specified by '.'s and can evaluate the path to a value
config.get('database.ip');