> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up JavaScript SDK

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

<View title="Federal docs">
  <Danger>
    **LaunchDarkly onboarding is not available in federal environments**

    To learn more, read <a href="/docs/home/infrastructure/federal">LaunchDarkly in federal environments</a>.
  </Danger>
</View>

Install and initialize the LaunchDarkly JavaScript SDK to start evaluating feature flags in your application.

## Install the package

<CodeGroup>
  ```shell title="yarn" lines wrap theme={null}
  yarn add @launchdarkly/js-client-sdk
  ```

  ```shell title="npm" lines wrap theme={null}
  npm i @launchdarkly/js-client-sdk
  ```

  ```shell title="pnpm" lines wrap theme={null}
  pnpm i @launchdarkly/js-client-sdk
  ```
</CodeGroup>

### Initialize the SDK for feature management

```tsx title="JavaScript SDK initialization" expandable lines wrap theme={null}
// A "context" is a data object representing users, devices, organizations, and
// other entities. You'll need this later, but you can ignore it for now.
const context = {
  kind: 'user',
  key: 'EXAMPLE_CONTEXT_KEY'
};
// This is your client-side ID.
const client = createClient('YOUR_CLIENT_SIDE_ID', context);
client.start();

const { status } = await client.waitForInitialization();

if (status === 'complete') {
  console.log('SDK successfully initialized!');
} else {
  console.error('Initialization failed');
}
```

### Initialize the SDK for feature management and Experimentation

If you want to use the LaunchDarkly [Experimentation](/docs/home/experimentation) feature, include a track call in your initialization code:

```js title="JavaScript SDK initialization for Experimentation" expandable lines wrap theme={null}
import { createClient } from '@launchdarkly/js-client-sdk';

// A "context" is a data object representing users, devices, organizations, and
// other entities. You'll need this later, but you can ignore it for now.
const context = {
  kind: 'user',
  key: 'EXAMPLE_CONTEXT_KEY',
  email: 'EXAMPLE_EMAIL',
};

// This is your client-side ID.
const ldClient = createClient('YOUR_CLIENT_SIDE_ID', context);

// await start — you only need waitForInitialization() if you wait somewhere
// other than where you start the client.
await ldClient.start();
console.log('SDK successfully initialized!');

// Call trackMetric when a metric action occurs in your app —
// a click, a form submit, a page view, a custom event, whatever your metric measures.
function trackMetric(metricKey, data) {
  ldClient.track(metricKey, data);
}
```

<Accordion title="Finding your SDK credentials">
  You can find your server-side SDK keys, mobile keys, and client-side ID on the **SDK keys** page under **Settings**.
</Accordion>

To learn more, read [Initialize the client](/docs/sdk/client-side/javascript#initialize-the-client) in the JavaScript SDK reference guide.
