etcd-simple-config

Simple config management with Etcd

Usage no npm install needed!

<script type="module">
  import etcdSimpleConfig from 'https://cdn.skypack.dev/etcd-simple-config';
</script>

README

etcd-simple-config

Simple config management with Etcd

npm install etcd-simple-config --save

See example.js

API

etcdConfig.bind(prefix, defaultConfig, changeCallback)

Bind etcd path prefix, providing the default config defaultConfig, get the current config and start watching for updates with changeCallback

var etcdConfig = new EtcdSimpleConfig('127.0.0.1', 4001);

var config = etcdConfig.bind(prefix, defaultConfig, function(key, change){
    console.log('Config changed', change, config);
});

config = etcdConfig.get(prefix)

Get config

etcdConfig.set(prefix, obj)

Add or update values

etcdConfig.toJSON(prefix)

Get config, merged with defaultConfig

Listening for events instead of using the change callback

Listen for the 'change' event

var config = etcdConfig.bind(prefix, defaultConfig, true);

config.on('change', function(key, change){
    console.log('on change', arguments);
});

or listen for a single field change

config.on('change:max_requests', function(key, change){
    console.log('on max_requests change', arguments);
});