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-nodeCreate 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();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