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

idiscovery

v0.1.0

Published

node中间件,支持服务自动发现,服务间通信,自动推选master服务,master服务crash后自动重新推选可用的服务作为master服务,支持added,removed,elected等事件监听。

Downloads

1

Readme

idiscovery

node中间件,支持服务自动发现,服务间通信,自动推选master服务,master服务crash后自动重新推选可用的服务作为master服务,支持added,removed,elected等事件监听。

Requirements

  1. requirements
    democracy >= 1.3.0 
    ip >= 1.1.5
    redis >= 2.8.0  

Usage

  1. install

    npm install idiscovery --save
  2. initialize

    var Discovery = require("idiscovery");
    new Discovery({
        name: 'idiscovery' // Your current service name
        interval: 1000, // The interval (ms) at which `hello` heartbeats are sent to the other peers.
        timeout: 3000, // How long a peer must go without sending a `hello` to be considered down.
        weight: Math.random() * Date.now() // The highest weight is used to determine the new leader. Must be unique for each node.
        id: 'uuid' // (optional) This is generated automatically with uuid, but can optionally be set. Must be unique for each node.
        redis: {} // Your redis config for connecting to a redis server.
    });
    
  3. Methods

    1. Returns the object containing all active nodes and their properties (including the one the method is called from).
    nodes()
    1. Returns the current leader node from the cluster.
    leader()
    1. Returns whether or not the current server is the leader.
    isLeader()
    1. If called on the current leader node, will force it to resign as the leader. A new election will be held, which means the same node could be re-elected.
    resign()
    1. Sends a custom event to all other nodes.
    send(customEvent, extraData)
  4. Events All events return the data/configuration of the affected node as their first parameter.

    1. Fired when a new peer has been found.
    added
    1. Fired when a peer has gone down and subsequently been removed from the list.
    removed
    1. Fired when a new leader is selected.
    leader
    1. Fired on the server that has become the new leader.
    elected
    1. Fired on the server that has resigned as the leader.
    resigned
    1. Fired on all the server except the one that "sent" the event.
    custom/all other events

Installation with npm

  • To install via Npm, simply do the following:

    执行install命令

        $ npm install idiscovery --save
       

    or

        $ vi package.json

    编辑package.json文件,添加如下配置:

        dependencies: {
            "idiscovery": "^0.0.1"
        }

    执行install命令

        $ npm install
       

Examples

The below example is easy to run on your local machine (also found in the test directory).

var Discovery = require('idiscovery');

var vote = new Discovery({
    name: "xxx",
    redis: {
        url: "redis://@127.0.0.1:6379/0",
        password: ""
    }
});

vote.on('added', function(data) {
  console.log('Added: ', data);
});

vote.on('removed', function(data) {
  console.log('Removed: ', data);
});

vote.on('elected', function(data) {
  console.log('You have been elected leader!');
});

vote.on('yyy', function(data) {
    console.log('yyy from %s', data.id, data.extra);
});

vote.send('yyy', {hello: 'world'});