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

@npmcorp/etcdjs

v2.4.7

Published

Low level etcd v2 client written in Javascript with failover support

Downloads

1,515

Readme

@npmcorp/etcdjs

npm fork of etcdjs

Low level etcd v2 & v3 client written in Javascript with failover support

npm install @npmcorp/etcdjs

Usage

Pass a connection string

var etcdjs = require('@npmcorp/etcdjs')
var store = etcdjs('127.0.0.1:4001')

store.set('hello', 'world', function(err, result) {
  store.get('hello', function(err, result) {
    console.log('hello:', result.node.value)
  })
})

If you have more than run instance of etcd running you can pass an array to load balance

var store = etcdjs(['127.0.0.1:4001', '127.0.0.1:4002', '127.0.0.1:4003'])

If you have a discovery token from https://discovery.etcd.io/ you can also pass that

var store = etcdjs('https://discovery.etcd.io/my-token')

etcdjs will automatically refresh its internal host list every 30s so you can transparently add more machines to your cluster without updating your seed host list.

API

store = etcd(host, opts)

host should be a etcd host (or an array of hosts) and opts default to

{
  refresh: false,        // refresh the interval host list automatically
  timeout: 60 * 1000,    // default timeout for ops
  json: false            // stringify/parse all values as JSON
}

Note: The refresh option will try to discover additional etcd hosts via the etcd /machines endpoint which may not always return hostnames which are routable. Make sure the endpoint returns what you expect before turning on this feature.

store.get(key, [opts], cb)

Get a key. opts defaults to

{
  recursive: false,
  sorted: false,
  json: false,      // parse value as JSON for this request
  wait: false,
  waitIndex: (none)
}

store.set(key, value, [opts], [cb])

Set a key. opts defaults to

{
  ttl: (none),
  dir: false,
  json: false,      // stringify value as JSON for this request
  prevExist: (none),
  prevValue: (none),
  prevIndex: (none)
}

store.update(key, value, [opts], [cb])

Set a key if it already exists. Same as set(key, value, {prevExists: true})

store.del(key, [opts], [cb])

Delete a key. opts defaults to

{
  recursive: false,
  dir: false,
  prevExist: (none),
  prevValue: (none),
  prevIndex: (none)
}

store.mkdir(key, [opts], [cb])

Create a directory. Same as set(key, null, {dir: true})

store.rmdir(key, [opts], [cb])

Remove a directory. Same as del(key, {dir: true})

store.wait(key, [opts], [cb])

Wait a key to change. Same as get(key, {wait: true}) except the callback is called with a third argument next that will wait for the next change.

store.wait('hello', function onchange (err, result, next) {
  console.log('change!', result);
  next(onchange); // next will set waitIndex so we do not miss events
});

.wait returns a destroy function which can be used to kill a waiting request.

var destroy = store.wait('hello', function onchange (err, result, next) {
  // ... do stuff ..
})

destroy()
store.set('key', 'value') // won't trigger the wait

store.compareAndSwap(key, value, prevValue, [opts], [cb])

Only set if prevValue matches previous value. Similar to set(key, value, {prevValue: prevValue})

store.compareAndDelete(key, prevValue, [opts], [cb])

Only delete if prevValue matches previous value. Similar to del(key, value, {prevValue: prevValue})

store.push(key, value, [opts], [cb])

Create an in-order key that is guaranteed to be greater than the previous push. Check result.key to see the actual key.

store.machines(cb)

Returns an array of all machines in the cluster

store.leader(cb)

Returns the leader of the cluster

store.destroy()

Destroy the client and all open connections

Stats

store.stats.self([node], cb)

Returns node stats

store.stats.store(cb)

Returns store stats

store.stats.leader(cb)

Returns leader stats

License

MIT