New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

zhike-consul

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zhike-consul

a simple consul client

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

zhike-consul

a simple consul client

Demo

const Consul = require('zhike-consul');
const configKeys = ['order', 'mq', 'userService', 'payService'];
const host = '127.0.0.1';
const port = 8500;

// 1.初始化consul
let consul = new Consul(configKeys, host, port, global);

// 2.加载相关配置
consul.pull().then(function() {
  // 3.构造全局config对象
  global.config = Object.assign({},
    CFG.order,
    {mq: CFG.mq},
    {userService: CFG.userService},
    {payService: CFG.payService}
  );
  // 4.启动HTTP Server
  let express = require('express');
  let app = express();
  let mq = amqplib.connect('amqp://' + config.mq.user + ':' + config.mq.pass + '@' + config.mq.host + ':' + config.mq.port);
  app.listen(config.port);
})

API

1.consul(configKeys, host, port, global)

Initialize a new Consul client

Options
  • configKeys(array), 想要获取的配置文件的key值, 如['db', 'redis']
  • host(string), default: 127.0.0.1
  • port(number), default: 8500
  • global, global.CFG可以获取到相关的配置
Usage
var Consul = require('zhike-consul');
var consul = new Consul(configKeys, host, port, global);

2.pull()

Get config values.

Usage
consul.pull().then(function() {
  console.log(CFG.redis.port);  // 6379
})

3.register(data)

Register current service

Options
  • data, 服务注册的数据
Usage
consul.register(data).then(function() {
  console.log('success');
})

4.getNodeIp()

Get ip address of consul service is running

Usage
consul.getNodeIp().then(function(data) {
  console.log(data);  // 172.16.3.2
})

Run Tests

npm test

FAQs

Package last updated on 17 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc