Quickstart
Create a flag, evaluate it from a Node.js script, and change its value from the dashboard.
This guide takes about ten minutes. At the end, a Node.js script reads a flag from Toggld, and you change the result from the dashboard without a deploy.
You need: Node.js 22 or later, and a package manager (pnpm, npm, or yarn).
Create an account and a workspace
Open toggld.io/start and sign up with GitHub or an email link.
Onboarding creates your first workspace. A workspace holds your flags, environments, segments, and credentials. It starts with two environments: Development and Production. Each environment has its own flag values and rules.
Onboarding can also create a first flag for you. This guide creates a separate flag so that you can follow each step.
Create a flag
- In your workspace, open Flags and select New flag.
- Under Basics, set Name to
New checkout. The Key becomesnew-checkout. Your code uses the key, and you cannot change it later. - Under Type, keep boolean.
- Under Variants, select set default on the
truevariant. Keepfalseas the off variant. - Under Environments, turn on Development. Keep Production off.
- Select Create flag.
The flag now serves true in Development, because it is on and it has no targeting rules. It serves false in Production, because it is off there.
Create a server SDK key
A server SDK key is a secret key that lets your server evaluate flags in one environment.
- Open Settings → API Keys.
- In the Development section, select Create key.
- Enter a Key name, such as
Quickstart. - Under Access, keep Server SDK key.
- Select Create key, then copy the key. It starts with
ffk_.
Toggld shows the full key only once. If you lose it, delete the key and create a new one.
Secret keys are shown only once, when you create them. Create a key
Needed for the Management API. Use a key with the management role.
Pasted keys stay in this browser tab and clear when you close it. The docs never send them anywhere. Only requests you run from the API playground use them.
Keep secret keys on your server. Never put them in browser code, mobile apps, or source control.
Install the SDK
Create a project folder and install @toggld/node. The SDK needs effect as a peer dependency, so install both.
pnpm add @toggld/node effectPut your key and the API URL in a .env file next to your script:
TOGGLD_SDK_KEY=ffk_YOUR_SECRET_KEY
TOGGLD_API_URL=https://api.toggld.ioAdd .env to your .gitignore file so that the key stays out of source control.
Evaluate the flag
Create index.mjs:
import { ToggldClient } from "@toggld/node";
const client = await ToggldClient.create({
sdkKey: process.env.TOGGLD_SDK_KEY,
endpoint: process.env.TOGGLD_API_URL,
});
const details = await client.getBooleanDetails("new-checkout", false, {
targetingKey: "user-123",
});
console.log(details.value, details.reason);
await client.close();Run it. The --env-file option tells Node.js to load your .env file:
node --env-file=.env index.mjsYou see this output:
true STATICSTATIC means that the flag is on and no targeting rule matched, so Toggld served the default variant. The second argument, false, is your fallback. The SDK returns it if evaluation fails for any reason, such as a network error or a wrong flag key.
Change the flag
- In the dashboard, open the
new-checkoutflag. - Select the Development tab.
- Under Who gets what, turn off the Development switch.
- Select Save Development.
Run the script again:
node --env-file=.env index.mjsfalse DISABLEDDISABLED means that the flag is off in this environment, so Toggld served the off variant.
You can also turn a flag on or off from the Flags list. The switch is in the Serving column, and it saves at once.
Changes are not instant. Caches and polling affect how fast a change reaches your application. If you still see the old value, wait up to a minute and run the script again. See update timing.