Getting Started with the Node SDK
Create the AppFlags Client
To create a new AppFlagsClient
:
const {AppFlagsClient} = require("appflags-node");
const appflagsClient = new AppFlagsClient("YOUR_SDK_KEY");
This will return immediately and the client will initialize asynchronously in the background.
You should only create one instance of AppFlagsClient
in your application. Creating multiple instances is inefficient and will log warnings in your application.
If you need to get feature flags from multiple AppFlags projects, you can create an AppFlagsClient
instance for each project.
Client Initialization
It takes the AppFlags client around 100ms to download your Feature Flag configuration from the AppFlags edge servers and fully initialize. Using the AppFlags client before initialization is complete will result in an error.
The client returns a promise that resolves when initialization is complete. You can get this promise by calling onInitialized
.
Using async/await:
await appflagsClient.onInitialized();
Using promises:
appflagsClient.onInitialized().then(() => {
// the client is initialized and ready to use
});