Node.js and Bun
@slydogdev/openfeature-provider
keeps your environment's rules in memory and evaluates flags in your process, so reading a
flag never waits on the network. Changes arrive over a stream within moments.
Install
npm install @slydogdev/openfeature-provider @openfeature/server-sdk
It's open source under Apache-2.0 and works with Node.js, Bun and other server-side JavaScript.
Set it up once
You need a server key (sly_srv_…) for one environment, from
that environment's SDK keys. Keep it on your server, like any secret.
import { OpenFeature } from "@openfeature/server-sdk"
import { SlydogProvider } from "@slydogdev/openfeature-provider"
await OpenFeature.setProviderAndWait(
new SlydogProvider({
sdkKey: process.env.SLYDOG_SERVER_KEY,
baseUrl: "https://api.slydog.dev",
}),
)
export const flags = OpenFeature.getClient()
Read flags
const on = await flags.getBooleanValue("new-checkout", false, { targetingKey: user.id })
const theme = await flags.getStringValue("theme", "light", { targetingKey: user.id })
const limit = await flags.getNumberValue("upload-limit-mb", 10, { targetingKey: user.id })
const config = await flags.getObjectValue("pricing", {}, { targetingKey: user.id })
The second argument is the default: what you get if the flag doesn't exist, has another
type, or no rules have loaded yet. To see why you got a value, use
getBooleanDetails and the others, which also return the
variant and reason.
Contexts
Pass attributes that rules can match next to the targetingKey. If your app
has more than one context kind, pass a multi-kind context:
await flags.getBooleanValue("nap-reminder", false, {
kind: "multi",
user: { targetingKey: user.id, plan: user.plan },
home: { targetingKey: home.id },
})
You can also set a context once with OpenFeature.setContext(…) or per request
with OpenFeature's
transaction context. See contexts and context kinds.
Options
| Option | Default | What it does |
|---|---|---|
sdkKey |
A server key for one environment, sly_srv_…. |
|
baseUrl |
https://api.slydog.dev, or your own server if you self-host. |
|
streaming |
true |
Stream changes as they happen. false polls instead. |
pollIntervalMs |
30000 |
How often to poll when streaming is off, and the longest wait between retries while the stream is down. |
reportEvaluations |
true |
Report which flags were evaluated, so Slydog can show when each was last used. |
file |
Read rules from a JSON file instead of Slydog. See below. | |
fetch |
global | A fetch to use instead of the global one. |
When Slydog can't be reached
Flags never take your app down. If Slydog is unreachable, the provider keeps evaluating with the last rules it had and keeps trying to reconnect, with a random wait so servers don't all come back at once. If it never loaded any rules, every flag returns the default you passed.
Tests and working offline
Read a ruleset from a JSON file instead. The provider watches the file and picks up changes, and never talks to Slydog:
new SlydogProvider({ file: "flags.json" })
What the provider sends to Slydog
-
Which flags were evaluated: flag keys only, at most once an hour per
flag. Never contexts or values. Turn it off with
reportEvaluations: false. - How many contexts it evaluated: each context's kind and a salted hash of its key, once a minute, to count monthly active users. Attributes and raw keys never leave your server.