Feature flags — enable/disable features without deploying.
1// Simple feature flag service2class FeatureFlags {3 constructor() {4 this.flags = new Map();5 }67 async init() {8 const flags = await fetchFlags();9 flags.forEach(f => this.flags.set(f.key, f));10 }1112 isEnabled(flagKey, context = {}) {13 const flag = this.flags.get(flagKey);14 if (!flag) return false;1516 // Percentage rollout17 if (flag.percentage !== undefined) {18 const hash = hashCode(context.userId || "anonymous");19 return (hash % 100) < flag.percentage;20 }2122 return flag.enabled;23 }24}2526const features = new FeatureFlags();27await features.init();2829// Usage in route30app.get("/dashboard", (req, res) => {31 const showNewUI = features.isEnabled("new-dashboard", {32 userId: req.user.id,33 });3435 if (showNewUI) {36 return res.render("dashboard-v2");37 }38 res.render("dashboard-v1");39});
Services: