Rollout.io

Rollout.io JavaScript SDK

Overview

The Rollout.io JavaScript SDK is an enterprise-grade, high-performance library designed for modern distributed web applications. Built with native ES Modules (ESM) support, it enables real-time feature flag evaluation and remote configuration management directly from the browser or Node.js runtimes.

Core Capabilities

Installation

Installation

Execute the following command in your project’s root directory:

npm install "@rollout.io/sdk-js@latest"

API Reference

The SDK exposes a singleton instance with the following public methods:

init(config)

Initializes the SDK and fetches the initial configuration state from the Control Plane. This must be called before evaluating any flags.

Parameters (config object):

Returns:

Example:

import sdk from '@rollout.io/sdk-js';

export const initRollout = async (userId) => {
    try {
        await sdk.init({
            sdkKey: 'YOUR_SDK_KEY',
            userId: userId,
            attributes: { role: 'admin', plan: 'premium' },
            baseUrl: 'http://rollout.paraglide.in/gateway', // Live Production Gateway (or "http://localhost:80/gateway" for local)
            refreshInterval: 30000        // Polling interval in milliseconds (30s)
        });
        console.log('Rollout.io SDK initialized successfully.');
    } catch (error) {
        console.error('Rollout.io Initialization failed:', error);
    }
};

getFlag(key, defaultValue)

Retrieves the evaluated value of a feature flag. This operates synchronously by reading from the internal cache populated during initialization. It also automatically dispatches telemetry to the Control Plane.

Parameters:

Returns:

Example:

// sdk.getFlag(String flagKey, boolean fallbackValue)
const isBannerEnabled = sdk.getFlag('hero-banner-v2', false);

if (isBannerEnabled) {
    // Render the new hero banner feature
    displayBanner();
} else {
    // Render the default fallback experience
    displayDefaultHeader();
}

onUpdate(callback)

Subscribes a listener that triggers whenever the remote configuration state changes. This is highly useful for reacting to live configuration updates fetched by the polling mechanism.

Parameters:

Example:

// Listen for real-time remote configuration changes
sdk.onUpdate((flags) => {
    console.log('Remote configuration state has been updated:', flags);
    
    // In React, you might trigger a state update here:
    // setFeatures(flags);
});

destroy()

Cleans up the SDK instance. It stops all active background polling threads and clears event listeners to prevent memory leaks. Use this during component unmounting or application teardown.

Parameters: None

Example:

// Unmount or cleanup function
function teardownApplication() {
    console.log('Shutting down Rollout.io SDK connections...');
    sdk.destroy();
}

Architecture and Directory Structure

Troubleshooting and Debugging


(C) 2026 Rollout.io Engineering Team