Back to Blog
TutorialFebruary 20265 min read

Feature Flags in 5 Minutes with Node.js + ToggleTown

Go from zero to feature flags in under 5 minutes. Install the SDK, initialize the client, wrap your feature, and ship with confidence.

Feature flags let you deploy code without releasing it. You push to production, but new features stay hidden behind a flag until you flip the switch. No more long-lived feature branches, no more "release day" anxiety.

In this tutorial, you'll add feature flags to a Node.js app using ToggleTown's Node SDK. The whole thing takes about 5 minutes.

1

Create a ToggleTown account

Sign up at app.toggletown.com — it's free for up to 5 flags, no credit card required. Create a project, and you'll get an environment API key (starts with env_).

2

Install the SDK

npm install @toggletown/sdk-node
3

Initialize the client

The SDK fetches your flag configuration on startup and evaluates flags locally — no network call per check, zero latency.

import { ToggleTownNode } from '@toggletown/sdk-node';

const client = new ToggleTownNode({
  apiKey: process.env.TOGGLETOWN_API_KEY, // env_xxx
});

await client.initialize();
console.log('ToggleTown ready —', client.flagCount(), 'flags loaded');

The SDK polls for updates every 30 seconds by default, so flag changes propagate without restarting your app.

4

Wrap your feature

Use getBooleanFlag to check whether a feature should be enabled. Pass the flag key, a default value, and an optional user context for targeting.

app.get('/dashboard', (req, res) => {
  const showNewDashboard = client.getBooleanFlag(
    'new-dashboard',
    false, // default if flag doesn't exist
    { userId: req.user.id, email: req.user.email }
  );

  if (showNewDashboard) {
    return res.render('dashboard-v2');
  }

  return res.render('dashboard');
});

The user context enables targeting rules — roll out to specific users, emails matching a pattern, or a percentage of traffic.

5

Create the flag in ToggleTown

Head to the ToggleTown dashboard, create a boolean flag called new-dashboard, and toggle it on. Your app picks up the change within 30 seconds.

Want to be more careful? Use percentage rollout to enable the flag for 10% of users first, then ramp up to 50%, then 100%. If something breaks, flip the flag off instantly — no deployment needed.

Beyond booleans

ToggleTown supports four flag types. Use the right one for your use case:

// Boolean — on/off toggles
const enabled = client.getBooleanFlag('new-feature', false);

// String — variant selection, themes, copy testing
const theme = client.getStringFlag('app-theme', 'light');

// Number — limits, thresholds, tuning
const maxRetries = client.getNumberFlag('max-retries', 3);

// JSON — complex configuration
const config = client.getJsonFlag('onboarding-flow', {
  steps: ['welcome', 'setup'],
});

Recap

  1. 1Sign up and get your environment API key
  2. 2npm install @toggletown/sdk-node
  3. 3Initialize the client with your API key
  4. 4Wrap features with getBooleanFlag (or other flag types)
  5. 5Create and toggle flags in the dashboard

Next steps

Ship features faster with flags

Free for up to 5 flags. No credit card required. Set up in 5 minutes.

Sign Up Free