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

trunker

v1.0.4

Published

A lightweight Express.js middleware to help you implement Trunk Based Development using feature flags.

Readme

Trunker

A lightweight Express.js middleware to help you implement feature flags. Easily manage and restrict access to routes based on static or dynamic flags, supporting both synchronous and asynchronous evaluation.

Features

  • Simple API for defining feature flags
  • Support for static and async flag evaluation
  • Restrict access to routes based on flags
  • Environment variable integration
  • TypeScript support out of the box

Installation

npm install trunker

Usage

Basic Example

import express from "express";
import { createTrunker } from "trunker";

const app = express();

const trunker = createTrunker({
  flags: {
    betaFeature: { active: true },
    legacyMode: { active: false },
  },
});

app.use(trunker.middleware());

// this route is accessible because betaFeature is active
app.get("/beta", trunker.restrict("betaFeature"), (req, res) => {
  res.send("Beta feature is enabled!");
});

// this route is not accessible because legacyMode is not active
app.get("/legacy", trunker.restrict("legacyMode"), (req, res) => {
  res.send("Legacy mode is enabled!");
});

app.listen(3000);

Restricting Access to Routes

You can restrict access to routes using the restrict middleware:

app.get(
  "/admin",
  trunker.restrict("betaFeature"),
  (req, res) => {
    res.send("Admin route with beta feature enabled");
  }
);

You can also restrict by multiple flags:

app.get(
  "/multi",
  trunker.restrict(["betaFeature", "legacyMode"]),
  (req, res) => {
    res.send("Route with multiple flags");
  }
);

Using Environment Variables

import { fromEnv, createTrunker } from "trunker";

const trunker = createTrunker(fromEnv(process.env));

Environment variables should be prefixed with TRUNKER_, e.g.:

TRUNKER_BETA=true
TRUNKER_LEGACY=false

Dynamic Flags

flags: {
  premiumUser: {
    active: async (req) => {
      // Custom logic, e.g., check user subscription
      return await checkUserSubscription(req.user);
    },
  },
}

Checking Flags Manually

import { isFlagActive } from "trunker";

app.get("/some-route", async (req, res) => {
  if (await isFlagActive(req, "betaFeature")) {
    res.send("Feature enabled");
  } else {
    res.status(403).send("Not available");
  }
});

Custom Error Responses

You can customize the error response format:

const trunker = createTrunker({
  flags: { ... },
  error: { 
    format: "json", // required. `json` or `plain` 
    key: "message",  // optional
    statusCode: 403, // optional
    template: "You can't access this route: {{flag}} is disabled" // optional
  }, 
});

API

createTrunker(options)

Creates the middleware. Pass an object with a flags property. Returns an object with middleware() and restrict() methods.

fromEnv(env, options?)

Generates flag configuration from environment variables.

isFlagActive(req, flagName)

Checks if a flag is active for the current request.

trunker.middleware()

Express middleware to attach flags to req.trunker.

trunker.restrict(flagName | flagName[])

Express middleware to restrict access based on one or more flags.

TypeScript

The middleware adds a trunker property to the Express Request type. You may need to import the type definitions for full type safety.

import { type Flags } from "trunker";

declare module "express-serve-static-core" {
  interface Request {
    trunker: Flags;
  }
}

License

MIT