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

@rustyconover/etcd-registry

v2.1.19

Published

Service registry for Node.js on top of etcd

Downloads

3

Readme

etcd-registry

Build Status Dependency Status

This is a fork of etcd-registry to accomplish a few goals:

  • Use etcd-node
  • Use ES6
  • Allow service entries to be monitored for changes
  • Add more robust tests
  • Add linting and code coverage tests

Service registry for Node.js on top of etcd

npm install etcd-registry

To install the command line tool

npm install -g etcd-registry
etcd-registry help

Usage

import Registry from 'etcd-registry';

// Pass the nodes in your cluster in a connection string
const services = new Registry('127.0.0.1:4001,127.0.0.1:4002,127.0.0.1:4003');

// Join the registry
services.join({ name: 'my-service-name', service: { port: 8080 }});

// Wait a bit and do a lookup
services.lookup('my-service-name', function(err, service) {
	console.log('Found the following service:');
	console.log(service);
});

Running the above example will produce the following output

Found the following service:
{
	name: 'my-service-name',
	port: 8080,
	hostname: '192.168.1.10',
	host: '192.168.1.10:8080',
	url: 'http://192.168.1.10:8080'
}

Full api

  • services = registry(connection-string) Create a new registry client
  • services = registry({ url: connection-url, maxRetries: 3, logger: loggerObject) Create a new registry client setting the maximum number of retries along with a Winston like logger object
  • services.join({ name, service, ttl }, [cb]) Join the registry with a new service
  • services.leave([name], [cb]) Leave the registry. Omit the name to remove local services
  • services.lookup(name, cb) Lookup a single service
  • services.list([name], cb) List all services as an array. Omit the name to list all services

Connection string

The connection has the following format

protocol://host1,host2,host3,.../namespace?options

The protocol can be https or http and defaults to http. If you set a namespace all keys will be prefixed with the value. If you do not specify a port in the hosts 4001 will be used (default etcd port).

Services

Services are just JSON documents. etcd-registry will add a default hostname and a couple of other properties. An example of a service document could be:

{
	name: 'my-service',
	port: 8080,
	hostname: '192.168.1.10',       // added by etcd-registry
	host: '192.168.1.10:8080',      // added by etcd-registry
	url: 'http://192.168.1.10:8080' // added by etcd-registry
}

These documents are saved in etcd with a default TTL of 10s.

The TTL is able to be managed by setting the key ttl in the call to service.join().

On an interval of the half of the TTL etcd-registry will send a heartbeat for each service to the registry which resets the expiration counter.

If possible you should call services.leave() before exiting your service process. Otherwise your service will be garbage collected after the TTL.

Fault tolerance

If a operation fails etcd-registry will try another node in the cluster until it has tried everyone.

Every once in a while etcd-registry will ping your cluster to see if new machines has joined and update the connection string

License

MIT