Node.js SDK

Evaluate flags on your server.
Without a request at runtime.

The Node SDK keeps an in-memory flag manifest for your process. Your request handlers evaluate flags synchronously, with the same deterministic bucketing used by the client SDK.

01 — Install

Install the package

Use a server API key from Settings → API Keys. Server keys are private credentials; never send one to a browser.

npm install experimentlab-node
02 — Initialize

Create one client per process

Initialize the client with your ExperimentLab URL and server key. It starts loading in the background by default. Await ready() only when you want the first manifest attempt to finish before serving traffic.

import { ExperimentNodeClient } from "experimentlab-node";

const flags = new ExperimentNodeClient({
  baseUrl: "https://flags.example.com",
  apiKey: process.env.EXPERIMENTLAB_SERVER_KEY!,
});

await flags.ready();
03 — Evaluate and track

Keep checks in-process

getFlag is synchronous. It does not query ExperimentLab, your database, or the network when a request arrives. Pass user attributes as context for targeting rules.

const showNewCheckout = flags.getFlag(
  user.id,
  "new_checkout",
  false,
  { plan: user.plan }
);

flags.track(user.id, "checkout_started", {
  currency: "USD",
});

Designed to fail quietly

Each process polls for a fresh manifest every 60 seconds. If a refresh fails, the SDK keeps using its last-known-good manifest and logs a warning. If it has never loaded one, getFlag returns your supplied default value.

  • No network request during flag evaluation
  • Last-known-good cache on API outages
  • Batched event tracking with retries
Need workspace-specific keys and setup?Open SDK setup