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 Environments section of your Project settings. Use the overflow menu next to the environment name to copy or display the needed key.

The environments list with the overflow menu open.

The Environments list with the overflow menu open.

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