Node.js
warning
The SDK is currently in beta.
Installation
npm install @withgates/node
or
yarn add @withgates/node
Usage
First, initialize the Gates service:
import { Gates } from "@withgates/node";
const gates = new Gates(process.env.GATE_PUBLIC_KEY!, {});
Initialize the Gates service
await gates.init();
Syncing Data
The SDK will automatically sync data from the server to the client. You can also manually sync data by calling the sync
method.
await gates.sync();
User Management
Sign in a user
Use your app's unique identifiers to sign in users.
const user = await gates.signInUser("<user-id>");
Set user attributes
The user attributes are used to target experiments, use them to create cohorts of users for your experiments. We have default attributes that are always available, but you can also add your own custom attributes. See User Attributes for more information.
const defaultAttributes = {
platform: "web",
}
const customAttributes = {
"custom-attribute": "custom-value",
}
await gates.setUserAttributes({
...defaultAttributes,
custom: {
...customAttributes,
}
});
Check if a knob is enabled
Knobs check does not require a user to be signed in.
const isEnabled = await gates.isEnabled("knob-name",);
Check if a user has access to a feature/experiment
The experiments are checked against the user's identity. If no user is signed in, it will always return false
.
const isInExperiment = await gates.isInExperiment("experiment-name",);