@configcat/sdk

中文文档
1.1.0发布于 2026/05/27MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 56.7万

ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.

原始使用文档
文档目录16 节
  1. Getting started
  2. 1. Install and import package:
  3. 2. Go to the ConfigCat Dashboard to get your SDK Key :
  4. 3. Create a ConfigCat client instance:
  5. 4. Get your setting value:
  6. Getting user-specific setting values with targeting
  7. Sample/demo apps
  8. Polling modes
  9. Sensitive information handling
  10. Package content
  11. Platform compatibility
  12. Troubleshooting
  13. Make sure you have the proper Node.js version installed
  14. Need help?
  15. Contributing
  16. About ConfigCat

ConfigCat SDK for JavaScript

JS SDK CI Quality Gate Status SonarCloud Coverage Known Vulnerabilities License JSDELIVR NPM

ConfigCat SDK for JavaScript provides easy integration for your application to ConfigCat.

This repository hosts the modern ConfigCat SDK for JavaScript platforms. Unlike the legacy platform-specific packages, it provides a single, unified NPM package that supports multiple JS environments.

The new SDK combines and, thus, supersedes these packages:

The new SDK maintains strong backward compatibility, making it a drop-in replacement for the packages listed above. In most cases you just need to replace the old package with the new one and adjust the import specifiers, as shown here.

Getting started

1. Install and import package:

via NPM

First install the NPM package:

npm i @configcat/sdk

Then import it into your application:

  • Frontend applications and Web Workers running in the browser:

    import * as configcat from "@configcat/sdk/browser";
    
  • Node.js backend applications:

    import * as configcat from "@configcat/sdk/node";
    
  • Deno backend applications:

    import * as configcat from "npm:@configcat/sdk/deno";
    

    To make this work, you may need to enable the unstable-byonm feature or adjust your import map.

  • Bun backend applications:

    import * as configcat from "@configcat/sdk/bun";
    
  • Cloudflare Workers:

    import * as configcat from "@configcat/sdk/cloudflare-worker";
    
  • Extensions for Chromium-based browsers (Chrome, Edge, etc.):

    import * as configcat from "@configcat/sdk/chromium-extension";
    

[!NOTE] Please note that subpath imports require your bundler to support the exports package.json field, introduced in Node.js v12.7. In the unlikely case of bundler compatibility issues, you can fall back to importing from the main entry point @configcat/sdk. Basically, this is another entry point to the Node.js build, however, if your bundler recognizes the browser package.json field, it will also work in your browser applications seamlessly.

[!NOTE] For subpath imports to work in TypeScript, you must set the moduleResolution option to node16, nodenext or bundler in your tsconfig.json. For TypeScript versions older than 4.7, where these options are not available, you need to fall back to module resolution node and importing from the main entry point @configcat/sdk.

via CDN

Import the package directly from a CDN server into your application:

  • Frontend applications and Web Workers running in the browser:

    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@configcat/sdk@latest/dist/configcat.browser.umd.min.js"></script>
    

    or

    <script type="module">
      import * as configcat from "https://cdn.jsdelivr.net/npm/@configcat/sdk@latest/dist/configcat.browser.esm.min.js";
    </script>
    
  • Extensions for Chromium-based browsers (Chrome, Edge, etc.):

    <script type="module">
      import * as configcat from "https://cdn.jsdelivr.net/npm/@configcat/sdk@latest/dist/configcat.chromium-extension.esm.min.js";
    </script>
    

2. Go to the ConfigCat Dashboard to get your SDK Key:

SDK-KEY

3. Create a ConfigCat client instance:

const configCatClient = configcat.getClient("#YOUR-SDK-KEY#");

[!NOTE] You can acquire singleton client instances for your SDK Keys using the getClient("<sdkKey>") factory function. (However, please keep in mind that subsequent calls to getClient() with the same SDK Key return a shared client instance, which was set up by the first call.)

4. Get your setting value:

The async/await way:

const value = await configCatClient.getValueAsync('isMyAwesomeFeatureEnabled', false);

if (value) {
  do_the_new_thing();
} else {
  do_the_old_thing();
}

or the Promise way:

configCatClient.getValueAsync('isMyAwesomeFeatureEnabled', false)
  .then((value) => {
    if (value) {
      do_the_new_thing();
    } else {
      do_the_old_thing();
    }
  });

Getting user-specific setting values with targeting

This feature allows you to get different setting values for different users in your application by passing a User Object to getValueAsync().

Read more about targeting here.

const userObject = { identifier: "#USER-IDENTIFIER#" };
const value = await configCatClient.getValueAsync('isMyAwesomeFeatureEnabled', false, userObject);

if (value) {
  do_the_new_thing();
} else {
  do_the_old_thing();
}

Sample/demo apps

Polling modes

The ConfigCat SDK supports 3 different polling strategies to fetch feature flags and settings from the ConfigCat CDN. Once the latest data is downloaded, it is stored in the cache, then the SDK uses the cached data to evaluate feature flags and settings. Read more about polling modes and how to use them at ConfigCat Docs.

Sensitive information handling

Frontend/mobile SDKs run in your users' browsers/devices. They download a config JSON file from ConfigCat's CDN servers. Since the SDK Key is included in the URL path of this file, your users can access both the SDK Key and the contents of the config JSON (including feature flag keys, feature flag values, targeting rules, percentage options, etc.)

However, the SDK Key provides read-only access: it only allows downloading your config JSON file, but it cannot be used to modify the corresponding config in your ConfigCat account.

If you want to prevent your users from accessing your SDK Key and the contents of your config JSON file, we recommend using the SDK in your backend services only. You can then provide a secure API endpoint for your frontend/mobile applications to evaluate feature flags and settings for your users.

Also, we suggest using confidential text comparators in the targeting rules of the feature flags and settings that are used in frontend/mobile SDKs.

Package content

Currently the @configcat/sdk NPM package includes the following builds of the library:

  • dist/configcat.browser.umd.min.js - for referencing the library in old browsers via a HTML <script> tag:
    • Uses the UMD bundle format.
    • Targets ES5 and includes all required polyfills.
    • TypeScript type definitions are not provided.
  • dist/configcat.browser.esm.min.js - for referencing the library in newer browsers via a HTML <script> tag:
    • Uses the standard ECMAScript module format.
    • Targets ES2015 and includes all required polyfills.
    • TypeScript type definitions are not provided.
  • dist/configcat.chromium-extension.esm.js - for referencing the library in Chromium-based browser extensions via a HTML <script> tag:
    • Uses the standard ECMAScript module format.
    • Targets ES2017 and includes all required polyfills.
    • TypeScript type definitions are not provided.
  • lib/cjs/ - for old versions of Node.js and bundlers not supporting ES modules:
    • Uses the legacy CommonJS module format.
    • Targets ES2017 and includes all required polyfills except for the Promise feature.
    • TypeScript type definitions are provided.
  • lib/esm/ - for modern versions of Node.js, Deno, Bun and bundlers:
    • Uses the standard ECMAScript module format.
    • Targets ES2017 and includes all required polyfills except for the Promise feature.
    • TypeScript type definitions are provided.

[!NOTE] Please note that the lib builds target a relatively new version of the ECMAScript standard. According to node.green, this is fully compatible with the supported Node.js versions. However, if you use a bundler and want to target browsers that have no ES2017 support, please make sure that your bundler is configured to downlevel the language syntax. If you want to go all the way down to ES5, then you will need to include a polyfill for the Promise feature as well.

Platform compatibility

This SDK should be compatible with all modern, widely used JS runtimes (execution engines) and bundlers.

The SDK is tested against the following runtimes:

  • @configcat/sdk/browser:
    • Chrome (stable, latest, beta)
    • Chromium (71.0.3556.0, 72.0.3626.0, 80.0.3987.0)
    • Firefox (84.0, latest, latest-beta)
    • Safari (latest)
  • @configcat/sdk/bun:
    • Bun (v1.1.0, latest stable) on Windows / Ubuntu / macOS
  • @configcat/sdk/deno:
    • Deno (v1.31, v1.46, latest stable) on Windows / Ubuntu / macOS
  • @configcat/sdk/node:
    • Node.js (v14.x, v16.x, v18.x, v20.x, v22.x, v24.x) on Windows / Ubuntu / macOS
  • @configcat/sdk/cloudflare-worker:
    • Workerd (2026-04-02)
  • @configcat/sdk/chromium-extension:
    • Chrome (stable, latest, beta)
    • Chromium (72.0.3626.0, 80.0.3987.0)

The SDK is compatible with TypeScript v4.0.2 or newer. Earlier versions may work but those are not tested, thus, not supported officially.

These tests are running on each pull request, before each deploy, and on a daily basis.

You can view a sample run here.

[!NOTE] We strive to provide an extensive support for the various JS runtimes and build tools. If you still encounter an issue with the SDK on some platform, please open a GitHub issue or contact support.

Troubleshooting

Make sure you have the proper Node.js version installed

You might run into errors caused by the wrong version of Node.js. To make sure you are using the recommended Node.js version follow these steps.

  1. Have nvm (Node Version Manager - https://github.com/nvm-sh/nvm ) installed:
  2. Run nvm install. This will install the compatible version of Node.js.
  3. Run nvm use. This will use the compatible version of Node.js.

Need help?

https://configcat.com/support

Contributing

Contributions are welcome. For more info please read the Contribution Guideline.

About ConfigCat

ConfigCat is a feature flag and configuration management service that lets you separate releases from deployments. You can turn your features ON/OFF using ConfigCat Dashboard even after they are deployed. ConfigCat lets you target specific groups of users based on region, email or any other custom user attribute.

ConfigCat is a hosted feature flag service. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.

版本与发布记录

@configcat/sdk 共发布 7 个版本,首次发布于 2024/11/09;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.0latest2026/05/275 个月前
1.0.22025/10/171.1 年前
1.0.12025/09/021.2 年前
1.0.02025/08/121.2 年前
0.1.12025/01/091.8 年前
0.1.02024/11/222 年前

关于 @configcat/sdk 的常见问题

@configcat/sdk 是什么?

ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.

如何安装 @configcat/sdk?

在项目目录运行 npm install @configcat/sdk,或使用 pnpm add / yarn add / bun add。

@configcat/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@configcat/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@configcat/sdk 可以商用吗?

@configcat/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@configcat/sdk 的下载量有多少?

根据 npm 官方下载统计,@configcat/sdk 在 2026/10/11 – 2026/11/09 这 30 天内被下载 566,565 次,日均约 18,886 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@configcat/sdk 还在维护吗?

最新版本 1.1.0 发布于 2026/05/27(5 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 1 个;首次发布于 2024/11/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。