@eppo/node-server-sdk

中文文档
4.0.0发布于 2026/01/28MITTypeScriptCommonJS近 30 天下载 35.1万

Eppo node server SDK

原始使用文档
文档目录9 节
  1. Features
  2. Requirements
  3. Installation
  4. Quick start
  5. Assignment functions
  6. Initialization options
  7. Assignment logger
  8. Export configuration
  9. Philosophy

Eppo Node SDK

Test and lint SDK

Eppo is a modular flagging and experimentation analysis tool. Eppo's Node SDK is built to make assignments in multi-user server side contexts. Before proceeding you'll need an Eppo account.

Features

  • Feature gates
  • Kill switches
  • Dynamic configuration
  • Progressive rollouts
  • A/B/n experiments
  • Holdouts
  • Mutually exclusive experiments (Layers)
  • Switchback experiments
  • Contextual Multi-armed bandits

Requirements

  • Node.js version 20.x or later

Installation

npm install @eppo/node-server-sdk

Quick start

Begin by initializing a singleton instance of Eppo's client. Once initialized, the client can be used to make assignments anywhere in your app.

Initialize once

import { init } from "@eppo/node-server-sdk";

await init({ apiKey: "<SDK-KEY-FROM-DASHBOARD>" });

Assign anywhere

import * as EppoSdk from "@eppo/node-server-sdk";

const eppoClient = EppoSdk.getInstance();

// Hypothetical user.
const user = getCurrentUser();

const variation = eppoClient.getStringAssignment(
  'new-user-onboarding', 
  user.id, 
  { country: user.country }, 
  'control'
);

Assignment functions

Every Eppo flag has a return type that is set once on creation in the dashboard. Once a flag is created, assignments in code should be made using the corresponding typed function:

getBoolAssignment(...)
getNumericAssignment(...)
getIntegerAssignment(...)
getStringAssignment(...)
getJSONAssignment(...)

Each function has the same signature, but returns the type in the function name. For booleans use getBooleanAssignment, which has the following signature:

getBoolAssignment: (
  flagKey: string,
  subjectKey: string,
  subjectAttributes: Record<string, any>,
  defaultValue: boolean,
) => boolean

Initialization options

The init function accepts the following optional configuration arguments.

OptionTypeDescriptionDefault
assignmentLoggerIAssignmentLoggerA callback that sends each assignment to your data warehouse. Required only for experiment analysis. See example below.null
requestTimeoutMsnumberTimeout in milliseconds for HTTPS requests for the experiment configurations.5000
numInitialRequestRetriesnumberNumber of additional times the initial configurations request will be attempted if it fails. This is the request typically synchronously waited (via await) for completion. A small wait will be done between requests.1
pollAfterFailedInitializationbooleanPoll for new configurations even if the initial configurations request failed.false
throwOnFailedInitializationbooleanThrow an error (reject the promise) if unable to fetch initial configurations during initialization.true
numPollRequestRetriesnumberIf polling for updated configurations after initialization, the number of additional times a request will be attempted before giving up. Subsequent attempts are done using an exponential backoff.7

Assignment logger

To use the Eppo SDK for experiments that require analysis, pass in a callback logging function to the init function on SDK initialization. The SDK invokes the callback to capture assignment data whenever a variation is assigned. The assignment data is needed in the warehouse to perform analysis.

The code below illustrates an example implementation of a logging callback using Segment, but you can use any system you'd like. The only requirement is that the SDK receives a logAssignment callback function. Here we define an implementation of the Eppo IAssignmentLogger interface containing a single function named logAssignment:

import { IAssignmentLogger } from "@eppo/node-server-sdk";
import { AnalyticsBrowser } from "@segment/analytics-next";

// Connect to Segment (or your own event-tracking system)
const analytics = AnalyticsBrowser.load({ writeKey: "<SEGMENT_WRITE_KEY>" });

const assignmentLogger: IAssignmentLogger = {
  logAssignment(assignment) {
    analytics.track({
      userId: assignment.subject,
      event: "Eppo Assignment",
      type: "track",
      properties: { ...assignment },
    });
  },
};

Export configuration

To support the use-case of needing to bootstrap your front-end client with an Eppo Client SDK, the Eppo NodeJS SDK provides a function to export flag configurations.

Use the getFlagConfigurations(): Record<string, Flag> function to export flag configurations, stringify them (or your preferred serialization method), and send it to the front-end client as a part of your routine initialization.

import express from 'express';
import * as EppoSdk from "@eppo/node-server-sdk";

const app = express();
const eppoClient = EppoSdk.getInstance();

app.get('/api/flag-configurations', (req, res) => {
  const flagConfigurations = eppoClient.getFlagConfigurations();
  res.json(flagConfigurations);
});

Philosophy

Eppo's SDKs are built for simplicity, speed and reliability. Flag configurations are compressed and distributed over a global CDN (Fastly), typically reaching your servers in under 15ms. Server SDKs continue polling Eppo’s API at 30-second intervals. Configurations are then cached locally, ensuring that each assignment is made instantly. Evaluation logic within each SDK consists of a few lines of simple numeric and string comparisons. The typed functions listed above are all developers need to understand, abstracting away the complexity of the Eppo's underlying (and expanding) feature set.

版本与发布记录

@eppo/node-server-sdk 共发布 61 个版本,首次发布于 2022/04/27;过去 12 个月发布了 1 个版本。

版本发布日期距今
4.0.0latest2026/01/289 个月前
3.12.12025/08/091.3 年前
3.12.02025/08/081.3 年前
3.11.02025/04/041.6 年前
3.10.22025/03/211.7 年前
3.10.12025/03/201.7 年前

其他发布通道:alpha.0 → 3.7.0-alpha.0,alpha → 3.7.1-alpha.1。

关于 @eppo/node-server-sdk 的常见问题

@eppo/node-server-sdk 是什么?

Eppo node server SDK

如何安装 @eppo/node-server-sdk?

在项目目录运行 npm install @eppo/node-server-sdk,或使用 pnpm add / yarn add / bun add。

@eppo/node-server-sdk 支持 TypeScript 吗?

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

@eppo/node-server-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@eppo/node-server-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.x。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@eppo/node-server-sdk 可以商用吗?

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

@eppo/node-server-sdk 的下载量有多少?

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

@eppo/node-server-sdk 还在维护吗?

最新版本 4.0.0 发布于 2026/01/28(9 个月前);至今共发布 61 个版本,其中过去 12 个月发布了 1 个;首次发布于 2022/04/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。