Skip to main content
Version: Next

Node.js

NPM Version NPM Downloads

Install dependencies

The first things we will do is install the Open Feature SDK and the GO Feature Flag provider.

yarn add @openfeature/server-sdk @openfeature/go-feature-flag-provider

Initialize your Open Feature client

To evaluate the flags you need to have an Open Feature configured in your app. This code block shows you how you can create a client that you can use in your application.

const {Sdk} = require("@openfeature/server-sdk");
const {GoFeatureFlagProvider} = require("@openfeature/go-feature-flag-provider");


// init Open Feature SDK with GO Feature Flag provider
const goFeatureFlagProvider = new GoFeatureFlagProvider({
endpoint: 'http://localhost:1031/' // DNS of your instance of relay proxy
});
OpenFeature.setProvider(goFeatureFlagProvider);
const featureFlagClient = OpenFeature.getClient('my-app')

Evaluate your flag

This code block explains how you can create an EvaluationContext and use it to evaluate your flag.

note

In this example, we are evaluating a boolean flag, but other types are also available.

Refer to the Open Feature documentation to know more about it.

// Context of your flag evaluation.
// With GO Feature Flag you MUST have a targetingKey that is a unique identifier of the user.
const userContext = {
targetingKey: '1d1b9238-2591-4a47-94cf-d2bc080892f1', // user unique identifier (mandatory)
firstname: 'john',
lastname: 'doe',
email: 'john.doe@gofeatureflag.org',
admin: true, // this field is used in the targeting rule of the flag "flag-only-for-admin"
// ...
};

const adminFlag = await featureFlagClient.getBooleanValue('flag-only-for-admin', false, userContext);
if (adminFlag) {
// flag "flag-only-for-admin" is true for the user
} else {
// flag "flag-only-for-admin" is false for the user
}

Features status

StatusFeatureDescription
Remote EvaluationThe provider is calling the remote server to evaluate the feature flags.
Tracking Flag EvaluationThe provider is tracking all the evaluations of your feature flags and you can export them using an exporter.
Configuration Change UpdatesThe provider is able to update the configuration based on the configuration, it means that the provider is able to react to any feature flag change on your configuration.
Provider Events ReactionsYou can add an event handler to the provider to react to the provider events.
ImplementedIn-progressNot implemented yet

Contribute to the provider

You can find the source of the provider in the open-feature/js-sdk-contrib repository.