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-locator

v1.1.6

Published

Come, resounding perception! The locator!

Downloads

1

Readme

consul-locator

For the older version, check docs at 1.0.3 docs

This is consul wrapper for discovery and detect a service changed.

Usage:

var locator = require('consul-locator')

use

Initialize a new locator wrapper

locator.use({host: '127.0.0.1'})

Options

  • host (String, default: 127.0.0.1): agent address
  • port (String, default: 8500): agent HTTP(S) port
  • secure (Boolean, default: false): enable HTTPS
  • ca (String[], optional): array of strings or Buffers of trusted certificates in PEM format
  • defaults (Object, optional): default options for method calls
  • promisify (Boolean|Function, optional): convert callback methods to promises

Service(serviceOptions)

Discovery a service

Options

  • service (String): service name

  • dc (String, optional): datacenter (defaults to local for agent)

  • tag (String, optional): filter by tag

    var service = new locator.Service('hello-world')

Methods:

  • watch: Listen to service changed
  • subscribe: subscribe to a key and listen to key changed

watch(callback)

sevice.watch((services) => {
    //Do with changed data
    console.log(services.next())
})

subscribe(key, callback)

service.subscribe('hello/tcp/port', (value) => {
  // Do something with changed value of key `hello/tcp/port`
  console.log(`tcp port has been changed to ${value}`)
});

ServiceFactory(serviceData)

next()

Get service by circular

/*
 * services = [10.0.0.1:123, 10.0.0.2:234]
 *
 */
services.next().ServiceAddress // 10.0.0.1:123
services.next().ServiceAddress // 10.0.0.2:234

isEmpty()

Check is services list is empty

services.isEmpty()

Iterator over services

for(var service of services) {
  console.log(service)
}

Discover helpers

locator.inject

Inject service as a query

locator.inject(['push-api', 'sms-api', (push_api, sms_api) => {
  console.log(push_api.ServiceAddess) // example: 10.60.3.32
}])

locator.$http

The http client wrapper for request API, It's working like request lib, but has some difference, the uri input could be like service://service-name/api/path

$http.get('service://hydra-web-api/users/17/online').then((res) => {
  console.log(res.status) // http status code
  console.log(res.body) // http response body
  console.log(res.response) // full response object
})

var data = {message: 'hello world'}
$http.post('service://hydra-web-api/users/17/messages', {
  headers: {
    'Authorization': 'd2226611-4ea8-40b8-a3ff-b789862ed522',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(data)
}).then((res) => {
  console.log(res.status)
}).catch((error) => {
  console.log(error)
})