Set up JavaScript SDK

Install the package

$yarn add launchdarkly-js-client-sdk

Initialize the SDK

JavaScript SDK initialization
1// A "context" is a data object representing users, devices, organizations, and
2// other entities. You'll need this later, but you can ignore it for now.
3const context: LDClient.LDContext = {
4 kind: 'user',
5 key: 'EXAMPLE_CONTEXT_KEY'
6};
7const client = LDClient.initialize('YOUR_CLIENT_SIDE_ID', context);
8
9client.on('initialized', function () {
10 console.log('SDK successfully initialized!');
11});

You can find your server-side SDK key, client-side ID, and mobile key in the “Resources” section of the help menu. Click the help icon at the bottom left corner of the LaunchDarkly UI, then choose SDK keys:

The SDK keys option in the help menu.

The SDK keys option in the help menu.

To learn more, read Initialize the client in the JavaScript SDK reference guide.