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

node-etcd3

v0.4.4

Published

node client for etcd (api v3)

Downloads

14

Readme

node-etcd3

Build Status CircleCI

a node client for the new etcd v3 grpc API

WIP: this client is work in Progress. Braking changes are avoided if possible, but may happen until the first stable version is reached

  • supports node 0.12, 4-6
  • easy to use
  • Promise based
  • offers sync methods
  • Docs: go here
    • may be broken/outdated until typedoc can handle typescript v2 (currently update v0.4.1, yay)
  • Changelog: go here
const { Etcd } = require("node-etcd3");
const etcd = new Etcd();

etcd.setSync("testKey", 34)
etcd.get("testKey").then(function (val) {
    console.log("testKey =>", val) // testKey => 34
    console.log("unset =>", etcd.getSync("unset")) // unset => null
})

Roadmap

working:

  • KV - get
  • KV - range
  • KV - set
  • KV - delete
  • Lease - grant
  • Lease - keep alive

todo for v1:

  • Lease - revoke
  • watch - watch
  • KV - compact

todo for later:

  • KV - txn
  • cluster
  • maintenance
  • auth

Intro & Examples

  • all methods return a Promise
  • most methods also come in a sync-flavor, like getSync for get
    • these are handy for setting up things on application start

get() and set() with Promises

etcd.get("env").then(function (env) {
    return etcd.set(env + "/testKey", 34)
}).then(function () {
    console.log("set testKey for env!")
}).catch(function (err) {
    console.error("error", err);
})

getSync()

const mainDB = new DB({
    server: etcd.getSync("db/main/server"),
    user: etcd.getSync("db/main/user"),
    password: etcd.getSync("db/main/password")
});

how to store a Object, Buffer, number, ... ?

etcd stores binary data (actually even the keys a buffers). But for ease of use node-etcd3 works with string most of the time. But you can still easily store a Buffer to etcd, just pass it into set().

  • a NodeJS Buffer will be stored it as-is.
  • strings also get stored as-is.
  • numbers will be stored as string.
  • any other object is put in JSON.stringify and stored as string

see below to see how to get a Buffer (or ...) out again

get & range return type

  • get offers multiple ways to return the data
  • value (default): returns a string
  • json: parses the value and return the parsed object
  • buffer: returns a NodeJS Buffer containing the value
  • raw: an object containing detailed information, such as the version or lease
  • they work for get() and range()
etcd.get("app/logo.png", "buffer");
etcd.get("app/config", "json");

leases

  • leases are basically etcd3 way of doing TTL for keys, but they work great for multiple keys at once
  • node-etcd3 has 3 main ways for working with leases
  • use the client lease
    the client has one managed lease, use "client" as lease ID then calling set(). It is kept alive automatically and you don't have a hand around the lease ID yourself.
    etcd.set("my/key", "hello leases!", "client")
  • use leases
    you can also get your own lease using the leaseGrant() method.
    let myVeryOwnLease = etcd.leaseGrant()
  • simply set a TTL
    you can pass in a number as lease to create a new lease with the TTL and use it for the key.
    etcd.set("ttl/key", "expire after 100s", 100);