A node.js client library for consul
This module attempts to be "low level" and follows consul's API pretty closely, meaning not a whole lot of sugar is provided for you. If you need something small, sugary and focused, use this module to build something higher level.
This not stable because is still being developed, feel free to help out!
$ npm install consul-node
The following options can be passed to the Consul
constructor.
host
-- The consul agent's host (defaults tolocalhost
).port
-- The consul agent's port (defaults to8500
).secure
-- Use https when talking to the agent (defaults tofalse
).strict
-- Treat HTTP 404's as errors (defaults tofalse
).
var Consul = require('consul-node');
var consul = new Consul({
host: 'localhost',
port: 8300,
});
Implements the KV endpoints.
- consul.kv.get(key, callback)
- consul.kv.put(key, data, callback)
- consul.kv.delete(key, callback)
TODO: flags, cas, recurse, blocking queries.
var consul = new Consul();
consul.kv.put('hello', 'world', function (err, ok) {
if (err) throw err;
consul.kv.get('hello', function (err, items) {
if (err) throw err;
console.log(items);
});
});
Implements the status endpoints.
- consul.status.leader(callback)
- consul.status.peers(callback)
var consul = new Consul();
consul.status.peers(function (err, peers) {
if (err) throw err;
console.log('peers -- %j', peers);
});
consul.status.leader(function (err, leader) {
if (err) throw err;
console.log('leader -- %s', leader);
});
Implements the agent endpoints.
- consul.agent.checks(callback)
- consul.agent.services(callback)
- consul.agent.members(callback)
TODO: everything else...
var consul = new Consul();
consul.agent.checks(function (err, checks) {
if (err) throw err;
console.log('checks -- %j', checks);
});
consul.agent.services(function (err, services) {
if (err) throw err;
console.log('services -- %j', services);
});
consul.agent.members(function (err, members) {
if (err) throw err;
console.log('members -- %j', members);
});
Implements the catalog endpoints.
TODO: everything...
Implements the health endpoints.
TODO: everything...