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 🙏

© 2026 – Pkg Stats / Ryan Hefner

discoverer

v1.0.15

Published

nodejs service discoverer

Downloads

28

Readme

discoverer

Build Status Coverage Status

nodejs service discover

in dev now. document will be wrote later, thanks

Architecture

arch

install

npm i discoverer --save

use server

const DiscovererServer = require('discoverer').DiscovererServer;

const server = new DiscovererServer();

server.start();

service provider

const restify = require('restify');
const DiscovererClient = require('discoverer').DiscovererClient;

const listenPort = process.env.PORT || 1234;

const server = restify.createServer();

const discovererClient = new DiscovererClient();

server.use(restify.queryParser());

server.get('/api/v1/add', function (req, res, next) {
  res.json({
    sum: parseInt(req.query.a) + parseInt(req.query.b)
  });
});

server.listen(listenPort, () => {
  console.log(`${server.name} listen on ${server.url}`)
})

discovererClient._registe(info => console.log(info))

service consumer

const DiscovererClient = require('discoverer').DiscovererClient;

// construct a new Discoverer client
const discover = new DiscovererClient();

// create a client load balance api client
const compute_server = discover.create_api_of('add-compute-service');

// wrap a request as a function
const add = (a, b) => {
  return compute_server
    .request(`/api/v1/add?a=${a}&b=${b}`, {
      json: true
    })
    .then(result => result.sum)
    .catch(err => {
      throw err;
    })
}

// another js file
add(1,2).then(console.log)
// out: 3

environment variable

All config items can be configured by system env variables

server

  1. USE_AUTH, default is false, set "true" will enable http digest auth
  2. AUTH_USER, avoid server access by un auth user, system will generte a random str if it not set
  3. AUTH_PASS, avoid server access by un auth user, system will generte a random str if it not set
  4. MONGO_CONNECT_URI, required, default is mongodb://localhost/discoverer
  5. LISTEN_HOST, default is 0.0.0.0
  6. PORT, default is 3999
  7. CHECK_INTERVAL, default is 2s, 服务器会每隔几秒检测数据库中是否有超时的instance,有的话就会移除记录

client

  1. C_SERVER_URL, default is http://127.0.0.1:3999, 如果server配置了http basic auth, 需要在url中指明,例如: http://discover.example.com
  2. C_AUTH_USER, use to pass the server auth
  3. C_AUTH_PASS, use to pass the server auth
  4. C_SERVICE_NAME, required, default is hostname, 服务名非常重要, consumer也是通过这个名称拉取provider列表
  5. C_INSTANCE_URL, required, default is http://yourip:80, 这里配置的地址是被外部服务远程调用的地址
  6. C_INSTANCE_ID, if not set, server will give you one
  7. C_HEART_BREAK_INTERVAL, default is 15s
  8. C_NO_REGISTE, default is false, if set this flag is true, client无论如何都不会注册到服务器,即使显式的调用了_registe方法

tasks

  • [x] mongodb storage
  • [x] move operate to service layer, [cancel]
  • [ ] add log
  • [x] client cli
  • [x] client default url is ip
  • [x] promisefy discoverer client
  • [x] api client, load balance, round method
  • [x] need a switch to adapt a client just want to consume services
  • [x] if there is not client info when renew, server should registe
  • [x] authorize should be more attention, security with http digest auth
  • [x] center config file
  • [ ] command line var
  • [ ] server side health check
  • [ ] when ApiClient catch an exception, should refresh client list