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

xyj-consul

v0.0.3

Published

smart sport consul service

Downloads

4

Readme

xyj-consul

结合smartsport项目架构使用,接口使用node-consul搭建,在node-consul的基础上封装易于结合smartsport项目使用的接口

Installation

install via NPM

$ npm install --save xyj-consul

Example Usage

创建实例:

const Consul = require('xyj-consul');

const consul = new Consul({host: '127.0.0.1', port: 8500}); // default: host-127.0.0.1, port-8500

服务注册:

const opts = {
  name: 'example',
  tags: ['example'],
  address: '127.0.0.1',
  servicePort: '10001'
};
consul.register(opts);

服务发现(格式化适用于web层):

consul.listFormat((err, result) => {
  if(err) throw err;
  console.log(result);
  /*
  { example: { host: '127.0.0.1', port: 8500 },
  example1: { host: '127.0.0.1', port: 8500 },
  example2: { host: '127.0.0.1', port: 8500 } }
  */
})

API

consul.register(options, callback)

Registers a new service.

Options

  • name (String): service name
  • id (String, optional): service ID
  • tags (String[], optional): service tags
  • address (String, optional): service IP address
  • port (Integer, optional): service port
  • check (Object, optional): service check
    • http (String): URL endpoint, requires interval
    • tcp (String): host:port to test, passes if connection is established, fails otherwise
    • script (String): path to check script, requires interval
    • dockercontainerid (String, optional): Docker container ID to run script
    • shell (String, optional): shell in which to run script (currently only supported with Docker)
    • interval (String): interval to run check, requires script (ex: 15s)
    • timeout (String, optional): timeout for the check (ex: 10s)
    • ttl (String): time to live before check must be updated, instead of http/tcp/script and interval (ex: 60s)
    • notes (String, optional): human readable description of check
    • status (String, optional): initial service status
    • deregistercriticalserviceafter (String, optional, Consul 0.7+): timeout after which to automatically deregister service if check remains in critical state
  • checks (Object[], optional): service checks (see check above)

Usage

consul.register('example', function(err) {
  if (err) throw err;
});

consul.list(callback)

Returns the services the agent is managing.

Usage

consul.list(function(err, result) {
  if (err) throw err;
});

Result

{
  "example": {
    "ID": "example",
    "Service": "example",
    "Tags": [
      "dev",
      "web"
    ],
    "Port": 80
  }
}

consul.listFormat(callback)

返回格式化后适合web服务层使用的列表格式

Usage

consul.listFormat(function(err, result) {
  if (err) throw err;
});

Result

{ 
  example: { 
    host: '127.0.0.1', 
    port: 8500 
  },
  example1: { 
    host: '127.0.0.1', 
    port: 8500 
  },
  example2: { 
    host: '127.0.0.1', 
    port: 8500 
  }
}

consul.consul

直接返回node-consul实例

TODO

  • all

License

@MIT