OpenFeature Server Provider
Use FeatureGate from OpenFeature-compatible server-side JavaScript applications.
Use @featuregate/openfeature-provider when your server application already evaluates flags through the OpenFeature API. The provider wraps the FeatureGate server SDK, so it uses secret server runtime keys, local snapshot evaluation, ETag caching, polling fallback, and optional streaming invalidation.
The OpenFeature provider uses a secret server runtime key and can load full environment snapshots. Keep it in trusted server processes. Browser applications should use publishable client keys with the OpenFeature Browser Provider, Browser SDK, or React SDK.
Install
npm install @featuregate/openfeature-provider @openfeature/server-sdk @openfeature/coreRegister the provider
setProviderAndWait waits until the provider has loaded the first FeatureGate snapshot, so later evaluations are backed by local FeatureGate data.
import { OpenFeature } from "@openfeature/server-sdk";
import { FeatureGateOpenFeatureProvider } from "@featuregate/openfeature-provider";
await OpenFeature.setProviderAndWait(
new FeatureGateOpenFeatureProvider({
runtimeApiKey: process.env.FEATUREGATE_RUNTIME_KEY!,
syncMode: "streaming",
}),
);
export const featuregate = OpenFeature.getClient();Evaluate flags
Use the standard OpenFeature client methods. The evaluation context is passed to FeatureGate targeting rules as attributes.
const enabled = await featuregate.getBooleanValue("new-checkout", false, {
user: { id: "user_123" },
account: { plan: "pro" },
});
const details = await featuregate.getBooleanDetails("new-checkout", false, {
user: { id: "user_123" },
});
console.log(details.reason, details.flagMetadata.featuregateReason);FeatureGate reasons are mapped into OpenFeature reasons and error codes. Missing flags and type mismatches return the caller fallback with OpenFeature error details instead of throwing.
Shutdown
When the process shuts down, clear or replace the provider so the underlying FeatureGate client closes its polling timer and snapshot stream.
await OpenFeature.clearProviders();