Featurevisor

SDKs

Node.js SDK

You can use the same Featurevisor JavaScript SDK in Node.js as well.

Installation

Install with npm:

$ npm install @featurevisor/sdk

API

Please find the full API docs in JavaScript SDK page.

OpenFeature

Use Featurevisor through the OpenFeature server SDK with the Node.js provider:

Command
$ npm install @featurevisor/openfeature-provider-node @openfeature/server-sdk
import { OpenFeature } from '@openfeature/server-sdk'
import { FeaturevisorOpenFeatureProvider } from '@featurevisor/openfeature-provider-node'
const provider = new FeaturevisorOpenFeatureProvider({
datafile,
})
await OpenFeature.setProviderAndWait(provider)
const client = OpenFeature.getClient()
const enabled = await client.getBooleanValue(
'checkout',
false,
{ targetingKey: 'user-123' },
)

Reusing an existing Featurevisor instance

If your application already owns a Featurevisor instance, pass it with the featurevisor option:

import { OpenFeature } from '@openfeature/server-sdk'
import { createFeaturevisor } from '@featurevisor/sdk'
import { FeaturevisorOpenFeatureProvider } from '@featurevisor/openfeature-provider-node'
const featurevisor = createFeaturevisor({ datafile })
const provider = new FeaturevisorOpenFeatureProvider({ featurevisor })
await OpenFeature.setProviderAndWait(provider)

The exact instance is also available as provider.featurevisor. Evaluations, datafile updates, modules, diagnostics, and events continue to use that instance.

Your application owns an instance passed this way. Provider shutdown does not close it, so other consumers can continue using it. Call featurevisor.close() when every consumer is finished. An instance created from provider options is owned and closed by the provider.

If featurevisor and Featurevisor construction options such as datafile or modules are supplied together, the existing instance takes precedence and the construction options are ignored. Provider options such as targetingKeyField, keySeparator, variationKey, and onTrack still apply.

See the OpenFeature provider guide for key conventions, variables, variations, errors, and providers for other languages.

OpenFeature example

See a complete Node.js application using the provider at featurevisor-example-openfeature-nodejs. It covers flags, variations, variables, context mapping, default values, and provider lifecycle.

Consuming the SDK

Require

If you are not dealing with ES Modules in Node.js, you can use require() as usual:

const { createFeaturevisor } = require('@featurevisor/sdk')

Import

If you want to take advantage of ES Modules, you can import the SDK directly:

import { createFeaturevisor } from '@featurevisor/sdk'

Example repository

You can find a fully working Node.js application using the Featurevisor SDK at featurevisor-example-nodejs.

Previous
JavaScript