ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.
npm install @configcat/sdk



!License


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:
* configcat-common
* configcat-js
* configcat-js-ssr
* configcat-js-chromium-extension
* configcat-node
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).
#### _via NPM_
First install the NPM package:
``PowerShell`
npm i @configcat/sdk
Then import it into your application:
* Frontend applications and Web Workers running in the browser:
`js`
import * as configcat from "@configcat/sdk/browser";
* Node.js backend applications:
`js`
import * as configcat from "@configcat/sdk/node";
* Deno backend applications:
`js`
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:
`js`
import * as configcat from "@configcat/sdk/bun";
* Cloudflare Workers:
`js`
import * as configcat from "@configcat/sdk/cloudflare-worker";
* Extensions for Chromium-based browsers (Chrome, Edge, etc.):
`js`
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:
`html`
or
`html`
* Extensions for Chromium-based browsers (Chrome, Edge, etc.):
`js`
`js`
const configCatClient = configcat.getClient("#YOUR-SDK-KEY#");
> [!NOTE]
> You can acquire singleton client instances for your SDK Keys using the getClient(" factory function.getClient()
> (However, please keep in mind that subsequent calls to with the _same SDK Key_ return a _shared_ client instance, which was set up by the first call.)
The async/await way:
`js
const value = await configCatClient.getValueAsync('isMyAwesomeFeatureEnabled', false);
if (value) {
do_the_new_thing();
} else {
do_the_old_thing();
}
`
or the Promise way:
`js`
configCatClient.getValueAsync('isMyAwesomeFeatureEnabled', false)
.then((value) => {
if (value) {
do_the_new_thing();
} else {
do_the_old_thing();
}
});
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.
`js
const userObject = { identifier: "#USER-IDENTIFIER#" };
const value = await configCatClient.getValueAsync('isMyAwesomeFeatureEnabled', false, userObject);
if (value) {
do_the_new_thing();
} else {
do_the_old_thing();
}
`
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.
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.
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