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 🙏

© 2025 – Pkg Stats / Ryan Hefner

knobs

v0.0.2

Published

Feature toggles

Downloads

8

Readme

Knobs

Easy feature toggles

Build Status

Install

npm install knobs

Usage

Define a list of features, each feature supports

  • name (required) - string for the feature name
  • env - a boolean environment variable for configuring the features. Takes precedence over the default value.
  • default - a boolean or function
var features = [
  { "name": "autorecovery", "env": "FEATURE_AUTORECOVERY", "default": false },
  { "name": "dynamic_scaling", "env": "FEATURE_DYNAMIC_SCALING", "default": false },
  { "name": "holiday_promo", "default": function(user) { return user.id % 2; } }
];
var Knobs = require('Knobs').default;
var knobs = new Knobs(features);

process.env['FEATURE_DYNAMIC_SCALING'] = true;
knobs.enabled('autorecovery'); // false
knobs.enabled('dynamic_scaling'); // true
knobs.enabled('holiday_promo', { id: 5 }); // true
knobs.enabled('holiday_promo', { id: 4 }); // false

Using Knobs allows for easy A/B testing. You could schedule future releases or slowly roll out by using a computed value:

knobs.load([
  {
    'name': 'foo',
    'default': function() {
      return Math.floor(Math.random()*10) % 2;
    }
  },
  {
    'name': 'bar',
    'default': function() {
      return new Date() > '02-12-2016';
    }
  }
]);

knobs.enabled(foo); // enabled for approx half of users
knobs.enabled(bar); // enabled after a certain date

Or you can manually override things with environment variables:

script.js

knobs.load({ name: 'foo', env: 'FEATURE_FOO', default: false });
console.log('Foo Enabled -', knobs.enabled('foo'));

Running without specified flags

$ node script
Foo Enabled - false

Running with flag on

$ FEATURE_FOO=true node script
Foo Enabled - true

API

constructor(features)

Create a new Knobs instance with a list of features.

.load

Load in a list of features.

.set(name, val)

Set the value of a feature. val can be a boolean or a function.

.enable(name)

Alias for .set(name, true)

.disable(name)

Alias for .set(name, false)

.enabled(name, [...args])

Returns whether a feature is enabled. Accepts optional parameters if the feature is defined by a computed value function.

.disabled(name, [...args])

Inverse of .enabled

Events

Knobs is an event emitter and emits on certain methods.

'load' event

When features are loaded, the "load" event is emitted with the list of features.

knobs.load(require('./features.json'));
knobs.on('load', (features) => { ... });

'change:[name]' event

Emitted when a feature changes via .set, .enable or .disable with the new feature value.

knobs.enable('launch redesign');
knobs.on('change:launch redesign', (val) => { ... });

License

MIT