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

consul-node

v0.0.2

Published

Client library for consul

Downloads

27

Readme

consul-node

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.

Warning

This not stable because is still being developed, feel free to help out!

Install

$ npm install consul-node

Configure

The following options can be passed to the Consul constructor.

  • host -- The consul agent's host (defaults to localhost).
  • port -- The consul agent's port (defaults to 8500).
  • secure -- Use https when talking to the agent (defaults to false).
  • strict -- Treat HTTP 404's as errors (defaults to false).
var Consul = require('consul-node');

var consul = new Consul({
  host: 'localhost',
  port: 8300,
});

General

Basically all calls support passing an optional parameter before the callback. This parameter is useful when wanting to pass query string parameters to the calls.

For example, this can be used to filter the services returned by the health endpoint.

// Get all nodes having the 'myservice' service
consul.health.service('myservice', function (err, nodes) {
    if (err) return console.error(err.stack);
    console.log('nodes -- %j', nodes);
});

// Get all healthy ('passing') nodes having the 'myservice' service
consul.health.service('myservice', {passing: 1 }, function (err, nodes) {
    if (err) return console.error(err.stack);
    console.log('nodes -- %j', nodes);
});

KV API

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);
  });
});

Status API

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);
});

Agent API

Implements the agent endpoints.

  • consul.agent.checks(callback)
  • consul.agent.services(callback)
  • consul.agent.members(callback)

Implemented but not yet covered by tests:

  • consul.agent.join(address, callback)
  • consul.agent.forceLeave(node, callback)
  • consul.agent.registerCheck(check, callback)
  • consul.agent.deregisterCheck(checkId, callback)
  • consul.agent.passCheck(checkId, callback)
  • consul.agent.warnCheck(checkId, callback)
  • consul.agent.failCheck(checkId, callback)
  • consul.agent.registerService(service, callback)
  • consul.agent.deregisterService(serviceId, callback)

TODO: Implement tests for the remaining calls.

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);
});

Catalog API

Implements the catalog endpoints.

Currently implemented:

  • consul.catalog.service(serviceName, callback)

TODO: Implement the remaining calls.

Health API

Implements the health endpoints.

  • node(node, callback)
  • checks(serviceName, callback)
  • service(serviceName, opts, callback)
  • state(state, callback)

The opts parameter can be used for filtering. Set it to {passing: 1} to add a query parameter to the request, which causes the Consul HTTP API to only return service nodes with passing checks.

Running tests

To run the tests, you have to have the Consul agent running locally.

Start the agent using:

// From the consul-node root folder
$ consul agent -config-dir=./test/config/consul.d

Then execute the tests using npm test.