Using the Node SDK
Node SDK Information
Local Execution
The AppFlags Node SDK evaluates Targeting Rules and returns Feature Flags locally in the client, rather than making a request to the AppFlags servers. This means there are no delays when using AppFlags in your Node app.
Automatic Updates
The AppFlags Node SDK listens for updates to your Feature Flags. When you update Feature Flags in the AppFlags dashboard, the AppFlags client is immediately notified and downloads the updated Feature Flags.
If you are interested in knowing about these updates, you can subscribe to a callback which is called whenever the client receives updated Feature Flags. See Get Notified When Feature Flags Update.
Providing User Data
Many calls to the AppFlags client require passing a user
object, which is needed to evaluate Targeting Rules for Feature Flags.
The user object contains a key
, which is a unique identifier for the user. This key must be unique for each user and stay the same for a particular user.
const user = {
key: "UNIQUE_USER_KEY"
}
Getting a Feature Flag
To retrieve a single Feature Flag, use the getFlag
function:
const flag = appFlagsClient.getFlag(user, "flag_key");
Getting All Feature Flags
To retrieve all Feature Flags, use the getAllFlags
function:
const flags = appFlagsClient.getAllFlags(user);
Get Notified When Feature Flags Update
The AppFlags client will automatically update whenever your Feature Flags change.
To get notified when Feature Flags update, you can subscribe to the onFlagsChanged
callback:
appflagsClient.onFlagsChanged(() => {
// feature flags have updated
});
Flag Properties
The Flag
object contains the following properties:
key
: the key identifier for the Feature Flagvalue
: the value of the active Variation, either aboolean
,number
, orstring
Example Repository
For a full example of using AppFlags in a Node application, see https://github.com/AppFlags/example-node.