OpenFeature provider for Node.js (server-side) SDK
OpenFeature provider for Node.js (server-side) SDK
OpenFeature provider for Node.js (server-side) SDK
This topic documents how to get started with the LaunchDarkly OpenFeature provider for the Node.js (server-side) SDK.
LaunchDarkly’s OpenFeature providers are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:
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.
The LaunchDarkly OpenFeature provider for the Node.js (server-side) SDK is compatible with the OpenFeature Node.js SDK v1.x.
The provider is compatible with Node.js 18 and above.
First, install the LaunchDarkly and OpenFeature packages:
Next, import the OpenFeature and LaunchDarkly namespaces in your application code:
After you install and import the provider, create a single, shared instance of LaunchDarklyProvider. Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.
Here’s how:
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.
A 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.
In the LaunchDarkly provider, contexts:
kind attribute.targetingKey, as in the OpenFeature specification, or key, which is the typical LaunchDarkly identifier for the targeting key.Here are examples of a context:
For additional examples, read OpenFeature specific considerations in the provider GitHub repository.
To evaluate feature flags for a context, use the OpenFeature Evaluation API. For example:
To associate metrics with actions customers take in your application, use the OpenFeature Tracking API. For example:
To learn more, read track.
You may need access to the LDClient from within the LaunchDarkly Node.js (server-side) SDK if you are working on use cases not supported by OpenFeature, such as migration flags or sending custom events.
To access the LDClient, use getClient():