# nacos-config

> nacos config client

Latest version **2.6.3** (published 2026-06-16) · 0 weekly downloads

## Install

```sh
npm install nacos-config
pnpm add nacos-config
yarn add nacos-config
bun add nacos-config
```

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.6.3 |
| Published | 2026-06-16 |
| First published | 2018-12-03 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 8.0.0 |
| Dependencies | 12 |
| Unpacked size | 406.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | czy88840616@gmail.com |
| Maintainers | czy88840616, gxcsoccer, sunrisea |
| Keywords | nacos-config, nacos |

## Links

- npm: https://www.npmjs.com/package/nacos-config
- npm.io page: https://npm.io/package/nacos-config

## Dependencies (12)

- [mz](https://npm.io/package/mz.md) ^2.7.0
- [debug](https://npm.io/package/debug.md) ^3.1.0
- [osenv](https://npm.io/package/osenv.md) ^0.1.5
- [urllib](https://npm.io/package/urllib.md) ^2.29.1
- [utility](https://npm.io/package/utility.md) ^1.14.0
- [sdk-base](https://npm.io/package/sdk-base.md) ^3.5.0
- [co-gather](https://npm.io/package/co-gather.md) ^1.0.0
- [urlencode](https://npm.io/package/urlencode.md) ^1.1.0
- [iconv-lite](https://npm.io/package/iconv-lite.md) ^0.4.24
- [is-type-of](https://npm.io/package/is-type-of.md) ^1.2.0
- [mz-modules](https://npm.io/package/mz-modules.md) ^2.1.0
- [cluster-client](https://npm.io/package/cluster-client.md) ^2.1.1

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 2.6.3 (latest) — 2026-06-16
- 2.5.2 (beta) — 2023-03-10
- 2.6.2 — 2026-05-12
- 2.6.1 — 2026-02-11
- 2.6.0 — 2023-12-14
- 2.5.1 — 2022-12-08
- 2.4.1 — 2022-05-09
- 2.4.0 — 2022-04-25
- 2.3.0 — 2022-04-25
- 2.2.1 — 2021-11-25
- 2.2.0 — 2021-09-29
- 2.1.1 — 2021-05-11
- 2.1.0 — 2021-02-19
- 2.0.1 — 2021-01-26
- 2.0.0 — 2019-05-07
- … 5 more at https://npm.io/package/nacos-config/versions

## README

# nacos-config

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

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

## Usage

```js
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](https://github.com/nacos-group/nacos-sdk-nodejs/blob/master/packages/nacos-config/src/interface.ts#L247)

默认值见 [ClientOptions 默认值](https://github.com/nacos-group/nacos-sdk-nodejs/blob/6786534c023c9b5200960363ff6c541707f4d3bf/packages/nacos-config/src/const.ts#L34)

### 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

* [@Harry Chen](https://github.com/czy88840616)

---
_Source: https://npm.io/package/nacos-config · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
