Integrate FlagSync feature flags into Node.js applications.
@flagsync/node-sdk
integrates into Node.js applications for server-side feature management and event tracking—ideal for backend services and APIs.
getFlagSyncUserContext
object.Promises
Events
FsUserContext
object. Pass this object to flag()
and track()
functions.
key
in FsUserContext
is unique and persistent for accurate MAU tracking and consistent flag evaluations. See User Context Best Practices for details.Create a Helper Function
key
is set using a persistent userId
or visitorId
from cookies, falling back to a generated ID with nanoid()
. For proper MAU tracking and consistent flag evaluations, ensure this key
is unique and persistent across requests—see User Context Best Practices.Set Cookies in Middleware (Optional)
getFlagSyncUserContext()
or elsewhere in your application.Use the Helper in Routes
FsUserContext
for flag evaluations or event tracking.flag()
, which applies targeting rules, rollouts, and defaults for the user context:
flag()
is called.defaultValue
or control
:
flag()
returns the server-evaluated value:
track()
function:
SDK_UPDATE
: Emitted when flags are updatedSDK_READY
: Emitted when the SDK is readyERROR
: Emitted when an error occurs during initializationSDK_UPDATE
does not fire if syncing is disabled.FsServiceError
.FsConfig
interface:
key
in FsUserContext
is unique and persistent for accurate MAU tracking and consistent flag evaluations. See User Context Best Practices for details.sync
object: stream
, poll
, or off
.
Stream (Default)
Polling
Off
stream
/poll
/off
) based on your application’s needs.FLAGSYNC_SDK_KEY
: Your server-side FlagSync SDK key (required)