npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

flagforge-node-sdk

v0.1.1

Published

Node.js Server-Side SDK for FlagForge

Readme

FlagForge Node.js SDK

Server-side SDK for FlagForge — a modern feature flag & A/B testing platform.

npm version License: MIT

Features

  • 🚀 Zero-latency evaluation — flags are cached in memory
  • 🎯 Deterministic hashing — consistent variant assignment per user
  • 🔀 Multivariate flags — support for A/B/n testing with JSON variants
  • 🔄 Auto-polling — keeps flags synced with configurable intervals
  • 📊 Built-in analytics — evaluation events tracked automatically
  • 🛡️ Offline resilient — gracefully handles network failures
  • 📦 TypeScript-first — full type definitions included

Installation

npm install flagforge-node-sdk

Quick Start

import { FlagForgeClient } from 'flagforge-node-sdk';

// 1. Initialize the client
const client = new FlagForgeClient({
  apiKey: 'your-project-api-key',
  apiUrl: 'https://your-flagforge-server.com', // default: http://localhost:4000
  refreshInterval: 60000, // poll every 60s (default)
});

await client.init();

// 2. Evaluate a boolean flag
const { enabled } = client.getVariant('dark-mode', 'user-123');

if (enabled) {
  // Show dark mode
}

// 3. Evaluate a multivariate flag (A/B test)
const { value, variantId } = client.getVariant('checkout-button', 'user-123', 'blue');

console.log(`Showing ${value} button (variant: ${variantId})`);
// Output: "Showing green button (variant: variant-b)"

// 4. Cleanup when done
client.close();

API Reference

new FlagForgeClient(config)

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | apiKey | string | required | Your project API key from the FlagForge dashboard | | apiUrl | string | http://localhost:4000 | URL of your FlagForge server | | refreshInterval | number | 60000 | Polling interval in ms (set to 0 to disable) |

client.init()

Fetches all flags from the server and starts background polling. Must be called before evaluating flags.

await client.init();

client.getVariant(flagKey, userId, defaultValue?)

Evaluates a flag for a specific user. Works for both boolean and multivariate flags.

| Parameter | Type | Description | |-----------|------|-------------| | flagKey | string | The flag key | | userId | string | Unique user identifier | | defaultValue | any | Fallback value if flag not found (default: null) |

Returns: EvaluationResult

interface EvaluationResult {
  enabled: boolean;     // Whether the flag is on for this user
  value: any;           // The variant value (true/false for boolean, any for multivariate)
  variantId?: string;   // The matched variant ID (multivariate only)
  reason: string;       // Why this result was returned
}

Example:

// Boolean flag
const { enabled } = client.getVariant('new-checkout', 'user-42');

// Multivariate flag with fallback
const { value } = client.getVariant('pricing-tier', 'user-42', 'free');

client.close()

Stops background polling. Call this when shutting down your server.

Events

client.on('update', () => {
  console.log('Flags refreshed from server');
});

client.on('error', (err) => {
  console.error('Failed to refresh flags:', err);
});

How It Works

Deterministic Hashing

FlagForge uses a deterministic hash of userId + flagKey to assign users to variants. This means:

  • ✅ Same user always sees the same variant
  • ✅ No database lookups required
  • ✅ Works offline after initial fetch
  • ✅ Consistent across server restarts

Evaluation Order

  1. Kill Switch — if flag is disabled, return off variant
  2. Blocked Users — if user is in block list, return off variant
  3. Allowed Users — if user is in allow list, return on/default variant
  4. Percentage Rollout — hash user into a bucket (0-99) and match against variant percentages

Express.js Example

import express from 'express';
import { FlagForgeClient } from 'flagforge-node-sdk';

const app = express();
const flags = new FlagForgeClient({ apiKey: process.env.FLAGFORGE_API_KEY! });

// Initialize flags before starting server
flags.init().then(() => {
  app.get('/api/pricing', (req, res) => {
    const userId = req.user.id;
    const { value } = flags.getVariant('pricing-page', userId, 'default');

    res.json({ layout: value });
  });

  app.listen(3000, () => console.log('Server running'));
});

License

MIT © FlagForge Team