FeatureGate

Server TypeScript SDK

Evaluate typed flags locally on trusted servers with polling, ETag caching, and streaming invalidation.

The server TypeScript SDK is built for trusted server-side applications. It uses secret server runtime keys, keeps the latest snapshot in memory, evaluates locally, and returns caller-provided defaults before the first snapshot is ready. Use the Browser SDK or React SDK for publishable client-key evaluation in browser code.

Server-only key

A server runtime key reads your full flag snapshot — keep it on the server and load it from an environment variable. For browser code, use a publishable client key with the Browser SDK.

Create a client

Create one client per runtime key and reuse it for the lifetime of the process. Choose streaming for near-instant invalidation, or polling when a long-lived connection is not practical.

featuregate.ts
ts
import { FeatureGateClient } from "@featuregate/server";

export const featuregate = new FeatureGateClient({
runtimeApiKey: process.env.FEATUREGATE_RUNTIME_KEY!,
syncMode: "streaming",
});

await featuregate.waitForReady({ timeoutMs: 2_000 });

Evaluate flags

Every evaluation takes an explicit default, so a call site is well-defined even before the first snapshot arrives or if a flag is removed.

checkout.ts
ts
const enabled = featuregate.isEnabled("new-checkout", {
defaultValue: false,
attributes: {
  user: { id: "user_123" },
  account: { plan: "pro" },
},
});

Testing & offline

For tests and local development, use offline and overrides so your app does not need a network call just to run a unit test. Call close() on shutdown to release the sync connection.

Close on shutdown

Call featuregate.close() when the process exits so the streaming connection and pending timers are released. In tests, offline: true with overrides evaluates flags with no network at all.

Next steps