0.0.2 • Published 9 years ago

node-etcdwatcher v0.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

Node Etcd watcher

"node-etcdwatcher" is simple libary, written in coffe-script for watching etcd directories for changes, and notifies you only when the keys have changed, and You get simple json dictionary of clean data!. It is a wrapper arround node-etcd, although the latest is not included as a depenndacy. In fact it has no dependencies at all. Insteam etcd-node connection option is accepted as constuctor parameter.

Example usage:

EtcdWatcher = require('node-etcdwatcher');
Etcd = require('node-etcd');
etcd = new Etcd(etcdHost, etcdPort);
redisHostWatcher = new EtcdWatcher(etcd);

redisHostWatcher.on('ok', function (key, val) {
    console.log("Setting redis config:", val);
    redisConfig.Host = val.host;
    redisConfig.Port = val.port;
});
redisHostWatcher.on('error', function (key, error) {
    console.log("Got error for key: $key:", error);
    redisConfig = {};
});
redisHostWatcher.once('ok', function (key, val) {

    redisConfig.Host = val.host;
    redisConfig.Port = val.port;
    some_service.start();
    console.log("Service started: ", val);
});
redisHostWatcher.watch("/redis");
console.log("Waiting for redis  config from", redisHostWatcher);

You can always call get_value() in order to fet the current (if any) value