ConfigCat SDK for JavaScript SSR
The `configcat-js-ssr` package provides an official ConfigCat SDK for integrating feature flags into Server-Side Rendered (SSR) JavaScript applications, such as those built with Nuxt.js or Vue.js. It allows developers to manage feature toggles remotely via the ConfigCat Dashboard, enabling the separation of releases from deployments and targeting specific user groups. Currently at version 8.5.3, this SDK is in maintenance mode, superseded by the unified ConfigCat SDK for JavaScript. It receives only critical security patches, with official support ending on August 31, 2026. Developers are strongly encouraged to migrate to the new unified SDK, which offers a consolidated experience for both browser and Node.js environments and removes the need for a separate SSR-specific SDK. Its key differentiator was its specialized focus on SSR environments, but this has been absorbed by the unified SDK.
Common errors
-
Error 1100: Your SDK Key seems to be wrong. Please check your SDK Key. (SDK_KEY: *****YOUR-SDK-KEY-PARTIAL)
cause The provided SDK Key for initializing the ConfigCat client is incorrect or malformed. The logged message now masks most of the key for security.fixVerify your SDK Key directly from the ConfigCat Dashboard. Ensure there are no typos, extra spaces, or missing characters. Copy-pasting directly is recommended. Also, check for environment variable issues if the key is loaded from there. -
TypeError: Cannot read properties of undefined (reading 'getValueAsync') or configCatClient.getValueAsync is not a function
cause The ConfigCat client instance was not correctly initialized, or the `getValueAsync` method is being called on an undefined or improperly imported object.fixEnsure `getClient()` is called with a valid SDK Key and that the returned client object is assigned and used. Also, verify that the `import { getClient } from 'configcat-js-ssr';` or `import * as configcat from 'configcat-js-ssr';` statement is correct and executes successfully.
Warnings
- breaking This SDK is superseded by the new unified ConfigCat SDK for JavaScript (configcat/js-unified-sdk). It is in maintenance mode and will only receive critical security patches.
- breaking Official support for `configcat-js-ssr` will end on August 31, 2026. After this date, no further updates, including security patches, will be provided for this package.
- breaking Multiple security vulnerabilities (CVE-2025-62718, CVE-2025-58754, CVE-2025-27152, XSS, etc.) have been found and fixed in the `axios` dependency across various `v8.x.x` releases. Running on older versions exposes applications to these risks.
- gotcha The `getClient("<sdkKey>")` factory function returns a singleton instance. While convenient, this means subsequent calls with the same SDK Key will return the same client, which might lead to unexpected behavior if different configurations are intended for different parts of an application lifecycle without explicit client disposal or unique SDK keys.
Install
-
npm install configcat-js-ssr -
yarn add configcat-js-ssr -
pnpm add configcat-js-ssr
Imports
- getClient
const configCatClient = require('configcat-js-ssr').getClient;import { getClient } from 'configcat-js-ssr'; - User
const User = require('configcat-js-ssr').User;import { User } from 'configcat-js-ssr'; - * as configcat
import configcat from 'configcat-js-ssr';
import * as configcat from 'configcat-js-ssr';
Quickstart
import { getClient, User } from 'configcat-js-ssr';
// Replace with your actual SDK Key from the ConfigCat Dashboard
const SDK_KEY = process.env.CONFIGCAT_SDK_KEY ?? 'YOUR_SDK_KEY';
async function initializeAndFetchFeatureFlags() {
if (SDK_KEY === 'YOUR_SDK_KEY') {
console.warn('Please replace YOUR_SDK_KEY with your actual ConfigCat SDK Key.');
}
const configCatClient = getClient(SDK_KEY);
// Example: Get a feature flag for a generic user
const isMyAwesomeFeatureEnabled = await configCatClient.getValueAsync('isMyAwesomeFeatureEnabled', false);
console.log(`'isMyAwesomeFeatureEnabled' for generic user: ${isMyAwesomeFeatureEnabled}`);
if (isMyAwesomeFeatureEnabled) {
console.log('Doing the new thing!');
} else {
console.log('Doing the old thing.');
}
// Example: Get a feature flag for a specific user
const userObject = new User('some-user-id'); // User ID can be any unique string
userObject.setEmail('user@example.com');
userObject.setCustom('region', 'eu');
const valueForSpecificUser = await configCatClient.getValueAsync('isMyAwesomeFeatureEnabled', false, userObject);
console.log(`'isMyAwesomeFeatureEnabled' for user 'some-user-id': ${valueForSpecificUser}`);
// Don't forget to close the client when done (e.g., on app shutdown)
// This ensures resources are released, especially important in environments like serverless functions.
configCatClient.dispose();
}
initializeAndFetchFeatureFlags();