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
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
})
working:
todo for v1:
todo for later:
getSync
for get
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);
})
const mainDB = new DB({
server: etcd.getSync("db/main/server"),
user: etcd.getSync("db/main/user"),
password: etcd.getSync("db/main/password")
});
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()
.
Buffer
will be stored it as-is.string
s also get stored as-is.number
s will be stored as string.JSON.stringify
and stored as stringsee below to see how to get a Buffer (or ...) out again
value
(default): returns a stringjson
: parses the value and return the parsed objectbuffer
: returns a NodeJS Buffer
containing the valueraw
: an object containing detailed information, such as the version
or lease
get()
and range()
etcd.get("app/logo.png", "buffer");
etcd.get("app/config", "json");
"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")
leaseGrant()
method.let myVeryOwnLease = etcd.leaseGrant()
etcd.set("ttl/key", "expire after 100s", 100);
Generated using TypeDoc