> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/feature-management-experimentation/new-to-fme/sdks-and-customer-deployed-components/openfeature-providers/nodejs-sdk.md).

# OpenFeature Provider for Node.js SDK

Integrate your Node.js applications with Harness FME using the Node.js OpenFeature Provider, a standardized, vendor-agnostic feature flagging API. This provider implements the OpenFeature specification and bridges the OpenFeature SDK with the Harness FME Node.js SDK.

This page walks you through installing, configuring, and using the Node.js OpenFeature provider to evaluate feature flags in your Node.js applications.

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

Before you begin, ensure you have the following:

* A valid [Harness FME SDK key](/feature-management-experimentation/new-to-fme/sdks-and-customer-deployed-components.md#api-keys) for your project
* A Node.js environment running version 14.x or later
* Access to `npm` or `yarn` to install dependencies

### Version compatibility <a href="#version-compatibility" id="version-compatibility"></a>

| Component                                      | Minimum Version |
| ---------------------------------------------- | --------------- |
| Node.js                                        | 14.x+           |
| `@splitsoftware/openfeature-js-split-provider` | ≥ 1.0.0         |
| OpenFeature Node.js SDK                        | ≥ 1.0.0         |

### Install the provider and dependencies <a href="#install-the-provider-and-dependencies" id="install-the-provider-and-dependencies"></a>

Install the Harness FME OpenFeature provider and required peer dependencies:

```bash
npm install @splitsoftware/openfeature-js-split-provider
npm install @splitsoftware/splitio
npm install @openfeature/server-sdk
```

### Initialize the provider <a href="#initialize-the-provider" id="initialize-the-provider"></a>

You can register the provider with OpenFeature in one of several ways, depending on your setup.

{% tabs %}
{% tab title="SDK API Key" %}
If you are using an SDK API key:

```javascript
const OpenFeature = require('@openfeature/server-sdk').OpenFeature;
const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-provider').OpenFeatureSplitProvider;

const authorizationKey = '<YOUR_SERVER_SIDE_SDK_KEY>'
const provider = new OpenFeatureSplitProvider(authorizationKey);
OpenFeature.setProvider(provider);
```

{% endtab %}

{% tab title="Split Factory (Recommended)" %}
If you are using a Split Factory:

```javascript
const OpenFeature = require('@openfeature/server-sdk').OpenFeature;
const SplitFactory = require('@splitsoftware/splitio').SplitFactory;
const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-provider').OpenFeatureSplitProvider;

const authorizationKey = '<YOUR_SERVER_SIDE_SDK_KEY>'
const splitFactory = SplitFactory({core: {authorizationKey}});
const provider = new OpenFeatureSplitProvider(splitFactory);
OpenFeature.setProvider(provider);
```

{% endtab %}

{% tab title="Split Client (Legacy)" %}
If you are using a Split client directly (not recommended for new implementations):

```javascript
const OpenFeature = require('@openfeature/server-sdk').OpenFeature;
const SplitFactory = require('@splitsoftware/splitio').SplitFactory;
const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-provider').OpenFeatureSplitProvider;

const splitFactory = SplitFactory({
  core: {
    authorizationKey: '<YOUR_SERVER_SIDE_SDK_KEY>'
  }
});
const provider = new OpenFeatureSplitProvider(splitFactory);
OpenFeature.setProvider(provider);
```

{% hint style="info" %}
The recommended approach is to pass the `splitFactory` instance instead of a splitClient. This ensures consistency with the JS Web Provider and allows future access to additional `splitFactory` features beyond the client itself.
{% endhint %}
{% endtab %}
{% endtabs %}

### Construct an evaluation context <a href="#construct-an-evaluation-context" id="construct-an-evaluation-context"></a>

Provide an evaluation context with a targeting key to evaluate flags. The evaluation context passes targeting information such as user IDs, email addresses, or plan types for flag targeting.

For example:

```javascript
const client = openFeature.getClient('<CLIENT_NAME>');

const context: EvaluationContext = {
  targetingKey: '<TARGETING_KEY>',
};
const boolValue = await client.getBooleanValue('boolFlag', false, context);
```

If the same targeting key is reused across evaluations, set the context at the client level:

```javascript
const context: EvaluationContext = {
  targetingKey: '<TARGETING_KEY>',
};
client.setEvaluationContext(context)
```

Or at the API level:

```javascript
const context: EvaluationContext = {
  targetingKey: '<TARGETING_KEY>',
};
OpenFeatureAPI.getInstance().setCtx(context)
```

Once the context is set at the client or API level, you don't need to provide it for each evaluation.

### Evaluate with details <a href="#evaluate-with-details" id="evaluate-with-details"></a>

Use the `get*Details(...)` APIs to get flag values and metadata (such as variant, reason, error code, and configuration). The FME treatment configuration is returned as a raw JSON string under `flagMetadata["config"]`.

For example:

```javascript
const booleanTreatment = await client.getBooleanDetails('boolFlag', false, context);
const config = booleanTreatment.flagMetadata.config
```

### Track events <a href="#track-events" id="track-events"></a>

The Harness FME OpenFeature provider supports tracking user actions or conversion events directly from your Node.js application.

To enable event tracking, your evaluation context must include the following:

* A non-empty `targetingKey`
* A [`trafficType`](/feature-management-experimentation/management-and-administration/traffic-types.md) (for example, `"user"` or `"account"`)
* A non-blank event name

Optionally, you can include a numeric value (defaults to 0) and additional event properties (prefers primitives such as string, number, boolean, or null). For more information, see [Sending Events](/feature-management-experimentation/management-and-administration/api-best-practices/events.md#event-record-fields).

For example:

```javascript
const context = { targetingKey: 'user-123', trafficType: 'account' }
const details = { value: 19.99, plan: 'pro', coupon: 'WELCOME10' }

client.track('checkout.completed', context, details)
```

For more information, go to the [Harness FME Node.js OpenFeature Provider GitHub repository](https://github.com/splitio/split-openfeature-provider-js).
