etcd client for node
Another (!!) etcd library for nodejs. This is formerly based on etcd-node, but has since evolved to a full-fledged new library with etcd v2 support.
This is not stable at the moment. Development will follow closely the development of etcd and changes in its API. minor-version changes will be kept in sync.
$ npm install nodejs-etcd
The client only need to be configured very simply by providing the base url of the etcd service.
var etcd = require'nodejs-etcd';var e =url: ''
Nodejs-etcd supports the full v2 api specification.
Reads from etcd. All paths you may want to read start with '/' as the etcd hierarchy strictly mimics the one of a filesystem
eread'key': '/hello'if err throw err;assertresultvalue;;
All etcd flags are supported here as well; the valid options are:
recursive(boolean) it set to true, fetches all subdirectories
wait(boolean) if set to true, the request will wait until the value changes.
wait_index(integer) if set toghether with wait, will wait to return until the marked index is reached
The callback can be encapsulated using this method. It will return a valid callback for the other methods that will:
- Manage HTTP response codes
- Populate a standard
- Apply resp_cb to this result.
Let's say we just want to output the value of the key:
cb = egeneratorconsole.log'An error has occurred'console.log'We found the key, it has value ' + resultvalueereadkey: '/hello'cb
By default, if no callback is declared nodejs-etcd will log some important values of the response to the console.
Writes a key or dir to the cluster. Simplest form:
ewritekey: 'hello'value: 'world'if err throw err;console.logbody;;
All etcd flags to a write operation are supported and must be added to the
- `ttl`` (integer) sets a TTL on the key
prev_exists(boolean) key gets written only if it is being created.
prev_index(integer) sets the key only if the actual index is exactly this one.
prev_value(string) sets the key only if the actual value is this one.
Deletes a key from etcd. If the
recursive option is set to true, it will allow to remove directories.
edel'hello'if err throw err;;
etcdmachinesif err throw err;;
etcdleaderif err throw err;;