@featurevisor/openfeature-provider-node

中文文档
4.8.0发布于 2026/11/14MITTypeScriptESM + CJS构建来源已验证近 30 天下载 1.9万

OpenFeature provider for Featurevisor in Node.js

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Featurevisor instance
  4. Let the provider create the instance
  5. Reuse an existing instance
  6. License

Featurevisor OpenFeature provider for Node.js

Use Featurevisor through the OpenFeature server SDK in Node.js.

Installation

npm install @featurevisor/openfeature-provider-node @openfeature/server-sdk

Usage

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',
  country: 'nl',
})

OpenFeature keys map to Featurevisor evaluations:

KeyEvaluation
checkoutflag
checkout:variationvariation
checkout:titlevariable named title
variable:supportEmailglobal variable named supportEmail

Use the resolver matching the Featurevisor value type. Boolean variables use the boolean resolver with a suffixed key. Arrays, objects, and JSON variables use the object resolver.

The provider maps OpenFeature targetingKey to Featurevisor userId by default. Configure targetingKeyField, keySeparator, variationKey, or globalVariablePrefix when your project needs different names. The global variable prefix defaults to variable.

The provider distinguishes an omitted targetingKey from an explicitly empty string. The OpenFeature server client passes both through, so { targetingKey: '', userId: 'old' } maps userId to the empty string. If no targeting key is supplied, an existing userId is preserved. Untyped JavaScript callers can also supply a finite numeric targeting key, including 0; NaN and infinity do not override the existing field.

Featurevisor instance

The provider can create and own a Featurevisor instance, or reuse one created by your application.

Let the provider create the instance

Pass normal Featurevisor options to the provider:

const provider = new FeaturevisorOpenFeatureProvider({
  datafile,
  modules,
  onDiagnostic,
})

The provider exposes the created instance as provider.featurevisor. You can use it for datafile updates, events, diagnostics, and other Featurevisor APIs. When OpenFeature closes the provider, the provider closes this instance and releases its resources.

Reuse an existing instance

Pass an instance created with createFeaturevisor() using 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 same instance is available as provider.featurevisor. Evaluations, datafile updates, modules, diagnostics, and events continue to use that instance.

An invalid initial datafile rejects setProviderAndWait with PARSE_ERROR, regardless of diagnostic log level. The provider remains in an error state until a valid datafile is supplied. Malformed updates emit an error event and resolve to the OpenFeature default with PARSE_ERROR. A valid update restores readiness, including when it restores the previously accepted datafile.

An instance passed this way remains owned by your application. Closing the OpenFeature provider does not close it, so other consumers can continue using it. Call featurevisor.close() when every consumer is finished.

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, globalVariablePrefix, and onTrack still apply.

See Featurevisor OpenFeature documentation for reasons, errors, metadata, tracking, lifecycle, and other language providers.

License

MIT © Fahad Heylaal

版本与发布记录

@featurevisor/openfeature-provider-node 共发布 10 个版本,首次发布于 2026/07/25;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.8.0latest2026/11/14今天
4.3.02026/10/2718 天前
4.0.12026/10/2025 天前
4.0.02026/10/1926 天前
3.8.02026/08/312 个月前
3.7.02026/08/292 个月前

关于 @featurevisor/openfeature-provider-node 的常见问题

@featurevisor/openfeature-provider-node 是什么?

OpenFeature provider for Featurevisor in Node.js

如何安装 @featurevisor/openfeature-provider-node?

在项目目录运行 npm install @featurevisor/openfeature-provider-node,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@openfeature/server-sdk(^1.23.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@featurevisor/openfeature-provider-node 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@featurevisor/openfeature-provider-node 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@featurevisor/openfeature-provider-node 可以商用吗?

@featurevisor/openfeature-provider-node 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@featurevisor/openfeature-provider-node 的下载量有多少?

根据 npm 官方下载统计,@featurevisor/openfeature-provider-node 在 2026/10/15 – 2026/11/13 这 30 天内被下载 19,433 次,日均约 648 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@featurevisor/openfeature-provider-node 还在维护吗?

最新版本 4.8.0 发布于 2026/11/14(今天);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/07/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。