Integrate FlagSync feature flags into Nest.js applications.
@flagsync/nest-sdk
integrates into Nest.js applications for server-side feature management and event tracking—ideal for backend services and APIs.
Configure the Module
FlagSyncModule
in your app.module.ts
:Inject the Client
@InjectFlagSync()
to inject the client into a Provider (e.g., service, controller, etc.):onModuleDestroy
lifecycle event to automatically destroy the FsClient
on application shutdown, releasing connections to FlagSync’s servers.To ensure proper cleanup, call enableShutdownHooks
during application startup. See the Nest.js documentation for Application ShutdownforRoot
:
forRootAsync
, ideal for dynamic configuration with ConfigService
:
FsClient
.
FsUserContext
object. Pass this object to flag()
and track()
functions.
This decorator enables passing @UserContext()
as a parameter in controller methods.
AuthGuards
, which can append user
incoming requests.key
in FsUserContext
is unique and persistent for accurate MAU tracking and consistent flag evaluations. See User Context Best Practices for details.flag()
is called.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.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)