Getting started

From nothing to a working feature switch in your code, in about five minutes.

This page walks through setting up your first switch and checking it from a Node.js service. If you're not using Node, the first three steps are the same, and the HTTP API covers the rest.

1. Create an environment

Switches live in environments, so you'll need one before anything else. Head to Feature Switches and click Create Environment.

Give it a name like prod or stage. Your first environment becomes the default, which just means it's the one Feature Switches opens on. You can change the default later under ⋮ → Edit.

Most teams want at least two: one for testing and one for production. Every switch exists in every environment, so add them whenever you like. When you add a new environment, every existing switch is added to it switched off.

2. Create a switch

Click Create Switch and fill in:

  • Name: what people will see, like New checkout.
  • Key: what your code asks for, like newCheckout. Letters, numbers, dots, dashes and underscores, up to 100 characters. It has to be unique, and it can't be changed later, so think about it for a second.
  • Description: optional, but we'd really recommend it. What does the switch do, and when can it be removed? Future you will thank you. Markdown is supported.
  • Default value: on or off. The switch starts with this value in every environment.

Switches are meant to be temporary. Once a feature has been fully rolled out, take the switch (and the old code path) out. Old switches have a habit of piling up, and nobody remembers what enableThing2 does six months later.

3. Create an API key

Pick the environment you want to use, then go to ⋮ → API keys and click to create one.

  • Name it after whatever will use it, like Checkout service. That way you know what breaks if you ever revoke it.
  • Choose Server for a backend service, or Client for a browser or mobile app. (Not sure? The key ideas explains the difference.)

Copy the key straight away. This is the only time you'll see it. Pop it in your secrets manager, or an environment variable. If you lose it, revoke it and make a new one. It's not a big deal.

4. Install the library

terminal
npm install @dev-team-tool/feature-switches-node

It needs Node 18 or later (or anything else with fetch), and it has no dependencies.

5. Check the switch

Create the client once when your service starts, and reuse it everywhere.

server.ts
import { createServerClient } from "@dev-team-tool/feature-switches-node";const switches = await createServerClient({  apiKey: process.env.FEATURE_SWITCHES_KEY,});if (switches.isEnabled("newCheckout", { userId: user.id })) {  // new checkout} else {  // old checkout}

Cool, that's it! Now go back to the switch in Feature Switches, flip its default, and save. Within 30 seconds your service picks up the change, no redeploy required.

Things worth knowing

  • Checks are instant. A server client downloads your rules and works the answers out in-process. isEnabled is a plain function call with no network request.
  • It never throws. If Dev Team Tools can't be reached, the client keeps using the last rules it loaded. If it never loaded any, you get the fallback (false, unless you say otherwise).
  • Keys can be revoked. Under ⋮ → API keys. It can take up to a minute for a revoked key to stop working everywhere.

Where next?