![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
zhike-consul
Advanced tools
a simple consul client
const Consul = require('zhike-consul');
const keys = ['orderPrivate', 'mq', 'userService'];
const host = '127.0.0.1';
const port = 8500;
const env = 'development';
// 1.初始化consul
let consul = new Consul(keys, host, port, global);
// 2.加载相关配置
consul.pull(env).then(function(data) {
/**
data = {
CFG: {
orderPrivate: {port: 6002, timeout: 10},
mq: {user: 'test', pass: 'test'},
userService: {url: 'http://api.dev.smartstudy.com/user'}
},
config: {
port: 6002,
timeout: 10,
mq: {user: 'test', pass: 'test'},
userService: {url: 'http://api.dev.smartstudy.com/user'}
}
}
*/
/** 每个key的配置信息会默认挂载在global的CFG对象下
global.CFG = data.CFG
*/
/** global的config对象会以私有配置为准,把其余的key的配置信息平铺在一起
global.config = data.config;
*/
// 3.启动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);
})
Initialize a new Consul client
var Consul = require('zhike-consul');
var consul = new Consul(keys, host, port, global);
Get config values.
consul.pull('development').then(function(data) {
console.log(data.CFG.redis.port); // 6379
console.log(data.config.redis.port); // 6379
// 或直接用global对象CFG和config
console.log(config.redis.port); // 6379
console.log(CFG.redis.port); // 6379
})
Register current service
consul.register(data).then(function() {
console.log('success');
})
Get ip address of consul service is running
consul.getNodeIp().then(function(data) {
console.log(data); // 172.16.3.2
})
npm test
FAQs
a simple consul client
The npm package zhike-consul receives a total of 12 weekly downloads. As such, zhike-consul popularity was classified as not popular.
We found that zhike-consul demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.