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
- Sign up and get your environment API key
npm install @toggletown/sdk-node- Initialize the client with your API key
- Wrap features with
getBooleanFlag(or other flag types) - Create and toggle flags in the dashboard
Next steps
- Read the full SDK docs for targeting rules, segments, and experiments
- Check out the feature flag best practices guide
- We also have SDKs for JavaScript, React, Python, and Go
ToggleTown is a simple, open feature flag platform for modern teams. Free tier available, no credit card required.
Top comments (0)