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

simple-service-registry

v0.1.1

Published

Simple wrapper around Etcd to help with the registration/discovery of distributed services and configuration

Downloads

5

Readme

Simple Service Registry

This module is a wrapper around Etcd, designed to assist with the registration and discovery of consumable microservices and associated configuration.

Installation and Setup

To install, npm install simple-service-registry.

To use:

const Registry = require('simple-service-registry')

const r = return new Registry({ 
	url: <Host of Etcd instance>
})

Optional params

This module uses request under the hood so any request parameter can be passed in as part of the options.

If you are using Etcd via Compose and want to use the supplied SSL certificate you can do:

const Registry = require('simple-service-registry')

const r = return new Registry({ 
	url: <Host of Etcd instance>,
	ca: fs.readFileSync("/path/to.cert.ca")
})

Alternatively, if you wish to ignore the SSL requirements, use strictSSL: false:

const Registry = require('simple-service-registry')

const r = return new Registry({ 
	url: <Host of Etcd instance>,
	strictSSL: false
})

Methods

There are a number of methods to help with the registration and discovery of services and configuration parameters.

.register( namespace, serviceName, serviceConfig, opts )

The .register() method will register a service in Etcd.

  • namespace is a string that defines a namespace for these services to be collected in (e.g. production, search, crm)
  • serviceName is a string that defines the name of the service
  • serviceConfig is a JSON object that defines the configuration needed to consume this service
  • opts is a JSON object that defines some options for the registration, such as a TTL.
const serviceConfig = {
  hostname: "http://search.example.com",
  api_key: "mylittlesecret"
}
r.register("production", "search-api", serviceConfig, { ttl: 30 })

The .register() method will register this service against Etcd every 10 seconds by default (or by the defined ttl). This means that once your app is stopped, the registration will expire within this time frame.

.service( namespace, serviceName )

The .service() method will attempt to discover a service by serviceName in a particular namespace.

This method returns an EventEmitter with events on:

  • set - when a service is registered (or re-registered)
  • expire - when a service registration expires
  • delete - when a service registration is deleted
r.service("production", "search-api")
.on("set", data => {
	// handle set event
})
.on("expire", data => {
	// handle expire event
})
.on("delete", data => {
	// handle delete event
})

.setEnv( namespace, envName, envValue, [callback] )

The .setEnv() method will set an environment parameter inside the provided namespace.

r.setEnv("production", "support-email", "[email protected]", (err, data) => {
	// handle optional callback
});

.getEnv( namespace, envName )

The .getEnv() method will attempt to discover environment parameters inside the provided namespace.

This method returns an EventEmitter with events on:

  • set - when a service is registered (or re-registered)
  • expire - when a service registration expires
  • delete - when a service registration is deleted
r.getEnv("production", "support-email")
.on("set", data => {
	// handle set event
})
.on("expire", data => {
	// handle expire event
})
.on("delete", data => {
	// handle delete event
})

Contributing

The projected is released under the Apache-2.0 license so forks, issues and pull requests are very welcome.