Using the JavaScript SDK

With your new-feature flag created, bring it into your app with the JavaScript SDK.

Check out our other SDKs for Node.js, Next.js, React, and more.

1

Install the SDK

Install the package via npm:

npm install @flagsync/js-sdk
2

Initialize the SDK

Create a client with your SDK key and a unique user identifier, such as user ID or email.

import { FlagSyncFactory } from '@flagsync/js-sdk';

const factory = FlagSyncFactory({
  sdkKey: 'your-sdk-key', // Replace with your SDK key
  core: {
    key: 'userId_0x123' // Unique identifier
  }
});

const client = factory.client();

Get your SDK key from your Workspace settings for the target Environment.

3

Wait for Readiness

Ensure the SDK is ready before checking flags:

await client.waitForReady();
console.log('SDK is ready!');
4

Evaluate Your Flag

Get the new-feature flag’s value:

const value = client.flag('new-feature', false);
console.log(value);

Calling flag() automatically logs an impression, tracking which variant each user sees—vital for metrics later.

5

Putting it all together

Here’s the full example:

import { FlagSyncFactory } from '@flagsync/js-sdk';

const factory = FlagSyncFactory({
  sdkKey: 'your-sdk-key', // Replace with your SDK key
  core: {
    key: 'userId_0x123' // Unique identifier
  }
});

const client = factory.client();

await client.waitForReady();
console.log('SDK is ready!');

const value = client.flag('new-feature', false);
console.log(value);

Next Steps

The SDK is ready—now track user actions: