Unleash Node.js Client

6.10.1 · active · verified Sun Apr 19

The `unleash-client` package provides a server-side SDK for Node.js applications to integrate with the Unleash feature management platform. It enables dynamic evaluation of feature flags, allowing developers to control feature rollouts, perform A/B testing, and manage configurations without redeploying code. The current stable version is 6.11.1, with frequent patch and minor releases addressing bug fixes, performance improvements, and new constraint types (like semver and CIDR). This client is designed for high performance and low overhead, maintaining an in-memory repository of feature toggles that are polled from the Unleash server at regular intervals. It supports both Unleash Enterprise and Open Source instances and is suitable for applications requiring robust and scalable feature flag capabilities. Key differentiators include its focus on server-side evaluation, asynchronous initialization with event-driven readiness signals, and support for various constraint types.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing the Unleash client, listening for readiness events, and evaluating a feature flag.

import { initialize } from 'unleash-client';

const unleash = initialize({
  url: 'https://unleash.example.com/api',
  appName: 'my-node-app',
  instanceId: 'my-unique-instance-id',
  customHeaders: { Authorization: process.env.UNLEASH_API_TOKEN ?? '' },
  refreshInterval: 15000 // Poll for updates every 15 seconds
});

unleash.on('error', console.error);
unleash.on('warn', console.warn);
unleash.on('ready', () => {
  console.log('Unleash client is ready!');
});
unleash.on('synchronized', () => {
  console.log('Unleash client has synchronized with the server.');
  if (unleash.isEnabled('my-feature-flag')) {
    console.log('Feature \'my-feature-flag\' is enabled!');
  } else {
    console.log('Feature \'my-feature-flag\' is disabled.');
  }
});

// Example of usage after initialization (ensure client is ready first)
setTimeout(() => {
  if (unleash.isEnabled('another-feature', { userId: '123' })) {
    console.log('Another feature is enabled for user 123.');
  } else {
    console.log('Another feature is disabled for user 123.');
  }
}, 5000);

view raw JSON →