OpenFeature Provider for Node.js SDK
Overview
The Node.js OpenFeature ProviderProviders act as a bridge between the Evaluation API and the underlying flag management system. They translate API calls into the format required by the provider, which could be a vendor SDK, a custom REST API, or a local data source. allows your Node.js applications to integrate with Harness FME using 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 flagsA feature flag is a conditional toggle in Harness FME that enables or disables specific functionality without deploying new code. It allows for controlled feature rollouts, A/B testing, and quick rollbacks if issues arise. in your Node.js applications.
Prerequisites
Before you begin, ensure you have the following:
- A valid Harness FME SDK key for your project
- A Node.js environment running version 14.x or later
- Access to
npmoryarnto install dependencies
Version compatibility
| 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
Install the FME OpenFeature provider and required peer dependencies:
npm install @splitsoftware/openfeature-js-split-provider
npm install @splitsoftware/splitio
npm install @openfeature/server-sdk
Initialize the provider
You can register the provider with OpenFeature in one of several ways, depending on your setup.
- SDK API Key
- Split Factory
- Split Client
If you are using an SDK API key:
const OpenFeature = require('@openfeature/server-sdk').OpenFeature;
const OpenFeatureSplitProvider = require('@splitsoftware/openfeature-js-split-provider').OpenFeatureSplitProvider;
const authorizationKey = '<YOUR_AUTH_KEY>'
const provider = new OpenFeatureSplitProvider(authorizationKey);
OpenFeature.setProvider(provider);
If you are using a Split Factory:
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_AUTH_KEY>'
const splitFactory = SplitFactory({core: {authorizationKey}});
const provider = new OpenFeatureSplitProvider(splitFactory);
OpenFeature.setProvider(provider);
If you are using a Split client:
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_AUTH_KEY>'
const splitClient = SplitFactory({core: {authorizationKey}}).client();
const provider = new OpenFeatureSplitProvider({splitClient});
OpenFeature.setProvider(provider);
Construct an evaluation context
Use an evaluation contextThe Evaluation Context holds contextual information used during flag evaluation. It can include static data (like application or host identifiers) and dynamic data (such as a client IP address), which can be passed explicitly or propagated automatically. Static and dynamic values can be merged for richer, more targeted evaluations. with a targeting keyA unique identifier used to target specific users or entities when evaluating feature flags. It helps determine which variation of a flag should be served based on predefined rules and conditions. to pass attributes used for flag targeting. You can include identifiers such as user IDs, email addresses, or plan types.
For example:
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:
const context: EvaluationContext = {
targetingKey: '<TARGETING_KEY>',
};
client.setEvaluationContext(context)
Or at the API level:
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
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:
const booleanTreatment = await client.getBooleanDetails('boolFlag', false, context);
const config = booleanTreatment.flagMetadata.config
Track events
The FME OpenFeature provider supports tracking user actions or conversion eventsEvents allow your application to respond to changes in provider state or flag configuration, such as readiness changes, errors, or updates to flag values. directly from your Node.js application.
To enable event tracking, your evaluation context must include the following:
- A non-empty
targetingKey - A
trafficType(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 example:
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, see the Harness FME Node.js OpenFeature Provider GitHub repository.