Feature flags for Express, Fastify, NestJS, and any Node.js backend
Sign up at flagbit.anethoth.com to get your SDK key. The free tier includes 1,000 evaluations/day.
npm install node-fetch
const fetch = require('node-fetch');
const FLAGBIT_SDK_KEY = process.env.FLAGBIT_SDK_KEY;
async function getFlag(flagKey, context = {}) {
try {
const res = await fetch(
'https://flagbit.anethoth.com/api/v1/evaluate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-SDK-Key': FLAGBIT_SDK_KEY
},
body: JSON.stringify({ flag_key: flagKey, context })
});
const data = await res.json();
return data.value;
} catch {
return false; // Safe default
}
}
// Express middleware
function featureGate(flagKey) {
return async (req, res, next) => {
const enabled = await getFlag(flagKey, {
user_id: req.user?.id,
plan: req.user?.plan
});
req.flags = { ...req.flags, [flagKey]: enabled };
next();
};
}
// Usage in Express routes
const express = require('express');
const app = express();
app.get('/api/search',
featureGate('elastic-search'),
async (req, res) => {
if (req.flags['elastic-search']) {
return res.json(await elasticSearch(req.query.q));
}
return res.json(await sqlSearch(req.query.q));
}
);
// NestJS guard
@Injectable()
class FeatureFlagGuard implements CanActivate {
async canActivate(context) {
const flagKey = Reflect.getMetadata('feature_flag', context.getHandler());
return await getFlag(flagKey);
}
}
Create reusable middleware that gates routes behind feature flags — clean, composable, and testable.
Route requests to new API handlers based on flags — migrate users gradually without breaking changes.
Read from both old and new database schemas simultaneously, compare results, then cut over.
Dynamically adjust rate limits for different user segments without redeploying.
Define flags in your FlagBit dashboard with targeting rules and rollout percentages.
Call the evaluate endpoint from your Node.js app with user context for targeted rollouts.
Enable, disable, or adjust rollouts in real-time. No redeployment needed.
Yes — implement a custom guard that evaluates flags via FlagBit API. Decorate controllers with @SetMetadata('feature_flag', 'flag-key').
Cache flag values in-memory with a TTL (e.g., 60 seconds). Only call FlagBit API when the cache expires.
Yes — FlagBit is a stateless HTTP API. Works perfectly with AWS Lambda, Vercel Functions, Cloudflare Workers.
Call the evaluate endpoint for each flag. For critical paths, evaluate in parallel with Promise.all().
Free tier includes 1 project, 10 flags, and 1,000 evaluations/day. No credit card required.
Get Your Free API Key