DEV Community

Cover image for How to Add Feature Flags to Your App in 5 Minutes
Jason Camp
Jason Camp

Posted on

How to Add Feature Flags to Your App in 5 Minutes

Feature flags are one of those things that seem optional until you need to roll back a broken feature at 2am on a Saturday.

Instead of reverting commits, redeploying, and praying — you just flip a toggle. Feature gone. Crisis over.

Here's how to add feature flags to your app in about 5 minutes.

What We're Building
A simple setup where you can:

  • Toggle features on/off instantly
  • Roll out features to a percentage of users
  • Use different settings per environment (dev/staging/prod)

Step 1: Get Your API Key
For this tutorial, I'm using SetBit — a feature flag service I built because I got tired of LaunchDarkly's complexity and pricing. Free tier works fine for this.

Sign up, create a project, and grab your SDK key from Account → API Keys.

Step 2: Install the SDK

npm install @setbit/js
Enter fullscreen mode Exit fullscreen mode

Or if you're using Python:

pip install setbit
Enter fullscreen mode Exit fullscreen mode

Step 3: Initialize

import { SetBit } from '@setbit/js';

const setbit = new SetBit({
  apiKey: 'your-sdk-key',
  environment: 'production'
});

await setbit.initialize();
Enter fullscreen mode Exit fullscreen mode

Step 4: Create Your First Flag
In the SetBit dashboard, click + Create Flag and set up:

Name: new-checkout-flow
Type: Boolean
Default: false

Step 5: Use It In Your Code

if (setbit.isEnabled('new-checkout-flow')) {
  return <NewCheckout />;
} else {
  return <OldCheckout />;
}
Enter fullscreen mode Exit fullscreen mode

That's it. Now you can toggle new-checkout-flow on or off from your dashboard — no redeployment needed.

Going Further: Percentage Rollouts

Want to test that new checkout with just 10% of users first?

Change your flag type to Rollout and set the percentage. SetBit handles the consistent bucketing so the same user always gets the same experience.

// Same code — rollout logic is handled server-side
if (setbit.isEnabled('new-checkout-flow', { userId: user.id })) {
  return <NewCheckout />;
}
Enter fullscreen mode Exit fullscreen mode

When to Use Feature Flags

  • Risky deployments — Ship the code, enable the feature later
  • A/B testing — Test variations with real users
  • Kill switches — Instantly disable a broken feature
  • Gradual rollouts — 10% → 50% → 100%
  • Beta features — Enable only for specific users

The Real Win
The peace of mind. Ship on Friday. If something breaks, flip a toggle from your phone. No laptop required.

I built SetBit for developers who want feature flags without the enterprise complexity or pricing. Free tier available if you want to try it. Feel free to contact me if you have any questions or feedback, I really appreciate it!

  • Jason

Top comments (0)