> ## 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.

# OpenFeature provider for Node.js (server-side) SDK

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

This topic documents how to get started with the LaunchDarkly OpenFeature provider for the Node.js (server-side) SDK.

<Note>
  **Provider quick links**

  LaunchDarkly's OpenFeature providers are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:

  <table>
    <thead>
      <tr>
        <th>Resource</th>
        <th>Location</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>OpenFeature Provider API documentation</td>
        <td>[Provider API docs](https://launchdarkly.github.io/js-core/packages/sdk/openfeature-node-server/docs/)</td>
      </tr>

      <tr>
        <td>GitHub repository</td>
        <td>[openfeature-node-server](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/openfeature-node-server)</td>
      </tr>

      <tr>
        <td>Sample application</td>
        <td>[Sample OpenFeature Node.js (server-side) provider application](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/openfeature-node-server/examples/getting-started)</td>
      </tr>

      <tr>
        <td>Published module</td>
        <td>[npm](https://www.npmjs.com/package/@launchdarkly/openfeature-node-server)</td>
      </tr>
    </tbody>
  </table>
</Note>

## Get started

The LaunchDarkly OpenFeature provider for the Node.js (server-side) SDK is intended for use in multi-user systems such as web servers and application. It is not intended for use in desktop and embedded systems applications.

Follow these instructions to start using the LaunchDarkly OpenFeature provider for the Node.js (server-side) SDK in your application.

### Version compatibility

The LaunchDarkly OpenFeature provider for the Node.js (server-side) SDK is compatible with the [OpenFeature Node.js SDK v1.x](https://openfeature.dev/docs/reference/technologies/server/javascript).

The provider is compatible with Node.js 18 and above.

## Install the provider

First, install the LaunchDarkly and OpenFeature packages:

<CodeGroup>
  ```bash title="Shell" lines wrap theme={null}
  npm install @openfeature/server-sdk
  npm install @launchdarkly/node-server-sdk
  npm install @launchdarkly/openfeature-node-server
  ```
</CodeGroup>

Next, import the OpenFeature and LaunchDarkly namespaces in your application code:

<CodeGroup>
  ```js title="LaunchDarkly Node.js (server-side) provider" lines wrap theme={null}
  import { OpenFeature } from '@openfeature/server-sdk';
  import { LaunchDarklyProvider } from '@launchdarkly/openfeature-node-server';
  ```
</CodeGroup>

## Initialize the provider

After you install and import the provider, create a single, shared instance of [`LaunchDarklyProvider`](https://launchdarkly.github.io/js-core/packages/sdk/openfeature-node-server/docs/classes/LaunchDarklyProvider.html). Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.

Here's how:

<CodeGroup>
  ```js title="JavaScript" lines wrap theme={null}
  await OpenFeature.setProviderAndWait(new LaunchDarklyProvider("YOUR_SDK_KEY"));

  const client = OpenFeature.getClient();
  ```
</CodeGroup>

<Note>
  **The Node.js provider uses an SDK key**

  The LaunchDarkly Node.js (server-side) provider uses an SDK key. Keys are specific to each project and environment. They are available on the **SDK keys** page under **Settings**. To learn more about key types, read [Keys](/docs/sdk/concepts/client-side-server-side#keys-and-credentials).
</Note>

## Construct a context

A [context](/docs/home/getting-started/vocabulary#context) is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. The OpenFeature specification calls these [evaluation contexts](https://openfeature.dev/docs/reference/concepts/evaluation-context).

In the LaunchDarkly provider, contexts:

* always have a particular [context kind](/docs/home/getting-started/vocabulary#context-kind). If you do not specify a kind, the provider treats the context as having a "user" kind. To specify a different kind, including a multi-context, you must include a `kind` attribute.
* must have a targeting key. This is optional in the OpenFeature specification, but LaunchDarkly requires a key for evaluation. You can specify this using `targetingKey`, as in the OpenFeature specification, or `key`, which is the typical LaunchDarkly identifier for the targeting key.

Here are examples of a context:

<CodeGroup>
  ```js title="Example user context" lines wrap theme={null}
  const context = {
  targetingKey: "example-user-key", // Could also use "key" instead of "targetingKey".
  };
  ```

  ```js title="Example organization context" lines wrap theme={null}
  const context = {
  kind: "organization",
  targetingKey: "example-user-key" // Could also use "key" instead of "targetingKey".
  };
  ```
</CodeGroup>

For additional examples, read [OpenFeature specific considerations](https://github.com/launchdarkly/js-core/tree/main/packages/sdk/openfeature-node-server#openfeature-specific-considerations) in the provider GitHub repository.

## Evaluate a context

To evaluate feature flags for a context, use the OpenFeature [Evaluation API](https://openfeature.dev/docs/reference/concepts/evaluation-api). For example:

<CodeGroup>
  ```js title="Evaluate a context" lines wrap theme={null}
  const flagValue = await client.getBooleanValue("example-flag-key", false, context);
  ```
</CodeGroup>

## Track metrics

To associate metrics with actions customers take in your application, use the OpenFeature [Tracking API](https://openfeature.dev/docs/reference/concepts/tracking). For example:

<CodeGroup>
  ```js title="Track a customer action" lines wrap theme={null}
  client.track('example-event-key', context, { "optionalCustomData": "optionalCustomValue"});
  ```
</CodeGroup>

To learn more, read [`track`](https://launchdarkly.github.io/js-core/packages/sdk/openfeature-node-server/docs/classes/LaunchDarklyProvider.html#track).

## Access the LaunchDarkly client

You may need access to the `LDClient` from within the [LaunchDarkly Node.js (server-side) SDK](/docs/sdk/server-side/node-js) if you are working on use cases not supported by OpenFeature, such as [migration flags](/docs/sdk/features/migrations) or [sending custom events](/docs/sdk/features/events).

To access the `LDClient`, use `getClient()`:

<CodeGroup>
  ```js title="JavaScript" lines wrap theme={null}
  const ldClient = provider.getClient();
  ```
</CodeGroup>
