This quickstart creates an environment, a flag and a server key, then evaluates the flag from a script with OpenFeature and EZGH’s server provider.
Before you start
- Node.js 20 or later, Bun or Deno.
- The
ezghCLI (install it), logged in, with a project selected (--projectorEZGH_PROJECT), andFlagsFullAccesson it (or the root user).
1. Create an environment, a flag and a key
ezgh flags envs create production
ezgh flags create new-checkout --name "New checkout"
ezgh flags toggle new-checkout --env production --on
export EZGH_FLAGS_SDK_KEY=$(ezgh flags keys create --env production --kind server --name quickstart)The flag is a boolean: on, with no rules, it serves true to everyone (its default rule). The
key is printed once.
2. Install
The provider isn’t published to npm yet: install it from GitHub by tag, with OpenFeature’s server SDK.
npm install @openfeature/server-sdk github:ezgamehost/flags-provider-ts#v0.1.03. Evaluate
import { OpenFeature } from "@openfeature/server-sdk"
import { EzghProvider } from "@ezgh/flags-openfeature/server"
await OpenFeature.setProviderAndWait(new EzghProvider({ sdkKey: process.env.EZGH_FLAGS_SDK_KEY! }))
const flags = OpenFeature.getClient()
const details = await flags.getBooleanDetails("new-checkout", false, { targetingKey: "user-1842", plan: "free" })
console.log(details.value, details.reason)Run it with node flags.ts (Node 22.18 or later), bun flags.ts or deno run -A flags.ts. It
prints true STATIC.
4. Change the targeting
Keep the new checkout from the free plan, then evaluate again:
ezgh flags config get new-checkout --env production > checkout.jsonAdd a rule to checkout.json’s rules:
{ "id": "0199a3c2-7a10-7c11-9b01-1f2e3d4c5b6a", "description": "Free plan", "clauses": [{ "attribute": "plan", "operator": "in", "values": ["free"] }], "serve": { "variation": "false" } }ezgh flags config set new-checkout --env production --file checkout.jsonThe script now prints false TARGETING_MATCH; a context with another plan still gets true
(reason DEFAULT). A long-running process gets the change within
seconds, without restarting.
How the server provider works
- It downloads the environment’s flags when it starts, and is ready once they’re loaded. Then it follows a stream of changes; if the stream fails it reads the flags every 30 seconds while it reconnects.
- Evaluation is local: no network call per evaluation.
- On a change it emits
PROVIDER_CONFIGURATION_CHANGEDwith the keys of the flags that changed. While it’s disconnected it keeps evaluating the last flags it had and emitsPROVIDER_STALE. endpointoverrideshttps://flags.ezghcloud.com.bootstrapPathstarts it from a file written byezgh flags export; withoffline: trueit uses only that file (tests, CI).
new EzghProvider({ sdkKey, bootstrapPath: "flags.json", offline: true })