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

nacos-config

v2.6.0

Published

nacos config client

Downloads

24,644

Readme

nacos-config

Nacos config client for Node.js 客户端 https://help.aliyun.com/document_detail/60137.html

重新使用了 typescript 编码,使用 async/await 重构。

Usage

import {NacosConfigClient} from 'nacos';   // ts
const NacosConfigClient = require('nacos').NacosConfigClient; // js

// 下面的代码是寻址模式
const configClient = new NacosConfigClient({
  endpoint: 'acm.aliyun.com', // acm 控制台查看
  namespace: '***************', // acm 控制台查看
  accessKey: '***************', // acm 控制台查看
  secretKey: '***************', // acm 控制台查看
  requestTimeout: 6000, // 请求超时时间,默认6s
});

// 下面的代码是直连模式
const configClient = new NacosConfigClient({
  serverAddr: '127.0.0.1:8848', // 对端的 ip 和端口,其他参数同寻址模式
});

// 主动拉取配置
const content= await configClient.getConfig('test', 'DEFAULT_GROUP');
console.log('getConfig = ',content);

// 监听数据更新
configClient.subscribe({
  dataId: 'test',
  group: 'DEFAULT_GROUP',
}, content => {
  console.log(content);
});

// 发布配置接口
const content= await configClient.publishSingle('test', 'DEFAULT_GROUP', '测试');
console.log('getConfig = ',content);

// 删除配置
await configClient.remove('test', 'DEFAULT_GROUP');

### Error Events 异常处理

```js
configClient.on('error', function (err) {
  // 可以在这里统一进行日志的记录
  // 如果不监听错误事件,所有的异常都将会打印到 stderr
});

NacosConfigClient 的 options 定义见 ClientOptions

默认值见 ClientOptions 默认值

API

获取配置

  • async function getConfig(dataId, group)
  • {String} dataId - 配置id
  • {String} group - 配置分组

发布配置

  • async function publishSingle(dataId, group, content)
  • {String} dataId - 配置id
  • {String} group - 配置分组
  • {String} content - 发布内容

删除配置

  • async function remove(dataId, group)
  • {String} dataId - 配置id
  • {String} group - 配置分组

订阅配置

  • function subscribe(info, listener)
    • {Object} info
      • {String} dataId - 配置id
      • {String} group - 配置分组
    • {Function} listener - 回调函数

取消订阅

  • function unSubscribe(info, [listener])
    • {Object} info
      • {String} dataId - 配置id
      • {String} group - 配置分组
    • {Function} listener - 回调函数(可选,不传就移除所有监听函数)

Contacts