npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nodejs-etcd

v0.1.1

Published

etcd client for node

Downloads

3

Readme

nodejs-etcd

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.

Notice

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.

Install

$ npm install etcd

Configuring.

The client only need to be configured very simply by providing the base url of the etcd service.

var etcd = require('etcd');

var e = new etcd({
    url: 'https://node01.example.com:4001'
})

Commands

Nodejs-etcd supports the full v2 api specification.

.read(options, [callback])

Reads from etcd. All paths you may want to read start with '/' as the etcd hierarchy strictly mimics the one of a filesystem

e.read({'key': '/hello', function (err, result, body) {
  if (err) throw err;
  assert(result.value);
});

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

.generator(err_cb, resp_cb)

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 EtcdResult object (see result.js)
  • Apply resp_cb to this result.

Let's say we just want to output the value of the key:

cb = e.generator(
    function () { console.log('An error has occurred')},
    function (result) { console.log('We found the key, it has value ' + result.value)}
)
e.read(
    {key: '/hello'},
    cb
)

By default, if no callback is declared nodejs-etcd will log some important values of the response to the console.

.write(options, [callback])

Writes a key or dir to the cluster. Simplest form:

e.write({
    key: 'hello',
    value: 'world',
    }, function (err,resp, body) {
  if (err) throw err;
  console.log(body);
});

All etcd flags to a write operation are supported and must be added to the options object.

Accepted options:

  • `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.

.del(options, [callback])

Deletes a key from etcd. If the recursive option is set to true, it will allow to remove directories.

e.del('hello', function (err) {
  if (err) throw err;
});

.machines(callback)

etcd.machines(function (err, list) {
  if (err) throw err;
});

.leader(callback)

etcd.leader(function (err, host) {
  if (err) throw err;
});

License

MIT