Node
Introduction
Our NodeJS SDK is a robust toolkit that enables developers to easily integrate feature flags into their Node.js applications. With our powerful dashboard, toggling features on and off is seamless and effortless, giving developers the ability to quickly and easily control feature releases in real-time.
Our SDK is designed to be flexible and scalable, providing intuitive APIs and extensive documentation to make integration easy and straightforward. With expert support and a wealth of resources at your fingertips, you can be confident that you have everything you need to build, deploy, and manage feature flags in your applications.
Whether you're a seasoned Node.js developer or just starting out, our SDK provides a comprehensive solution for integrating feature flags into your applications, giving you the power to deliver new features to your users with confidence and ease. So why wait? Try our NodeJS SDK today and see how it can transform your feature flagging process.
Installation
Here are three simple steps to get started with our Node SDK:
Install the SDK by running the following command:
yarn add @flagga/nodeThis will install all the necessary packages to enable feature flag integration in your Node.js application.
Import the SDK by adding the following line of code to your application:
import { SDK } from '@flagga/node';This will allow you to use the SDK's powerful tools and features.
Use the SDK to control feature releases in your application. Create an instance of the SDK with your API key and project ID by adding the following code:
const sdk = new SDK({
apiKey: API_KEY,
projectId: PROJECT_ID,
});Once you have created an instance of the SDK, you can start using its powerful dashboard and intuitive APIs to control and manage feature releases in real-time.
API reference
getProject
Returns the project information for the active project.
Syntax
async getProject(): Promise<Project | null>
Example
const sdk = new SDK(apiKey, projectId);
const project = await sdk.getProject();
console.log(project);
Description
This function retrieves the project information for the active project using the SDK's apiKey, apiUrl, and projectId. If the operation is successful, the project information is stored in the SDK's project property. If an error occurs, a console error is logged, and null is returned.
updateRules
Updates local SDK with most recent rules from the API.
Syntax
async updateRules(): Promise<null>
Example
const sdk = new SDK(apiKey, projectId);
await sdk.updateRules();
Description
This function fetches the latest changes from the web and saves them in the SDK to be used for subsequent flag checks. It updates the local features and segments with the fetched data and sets the isReady flag to true.
flag
Retrieve the status of the flag for a specific user.
Syntax
flag(featureFlag: string, user: User): Variation
Example
const sdk = new SDK(apiKey, projectId);
const user = { id: '1234', country: 'US', language: 'en' };
const isFeatureEnabled = sdk.flag('myFeatureFlag', user) === FeatureServe.ON;
Parameters
featureFlag: A string representing the feature flag to check for.
user: An object containing user parameters for which the feature flag status needs to be determined.
Description
This function checks the status of the feature flag for a specific user. It uses the features and segments fetched from the API to determine the status of the feature flag for the given user. If the SDK has not finished loading, it returns the default value of FeatureServe.CONTROL. The function returns the status of the feature flag for the given user as a Variation enum value.
allFlags
Returns an array of objects that represent the feature flag state for the specified user.
Syntax
allFlags(user: User): Flag[]
Example
const sdk = new SDK(apiKey, projectId);
const user = {
id: 'user123',
email: 'user123@example.com',
custom: {
country: 'US',
plan: 'premium'
}
};
const flags = sdk.allFlags(user);
console.log(flags);
Description
This function returns an array of objects representing the feature flag state for the specified user. Each object contains the variation value and feature key for a single feature flag.
The function loops through all the features and calculates the variation for each feature flag based on the user object and segments. It then returns an array of objects containing the variation and the feature key for each feature flag.
The function also emits a create_user event, passing the user object, to allow the SDK to keep track of how many unique users are using the application.