neff

nconf & express based features flags

The standard way to use neff on the client & the server side is to check for enabled features using the isEnabled() API.

var users = 500;
var moreUsers = neff.isEnabled("moreUsers");
if (moreUsers) {
    users++;
}

To get started with neff you'll want to make sure you have setup nconf to contain a features setting, which is an object with feature names and either true or false values. I'm currently doing this using a JSON file and my config looks like this:

"features"{
    "feature1": true,
    "feature2": false
}

Neff provides a middleware to add feature flag information to express views. Its usage is:

app.use(neff.helpers);

The first thing it allows you to do is access feature flags directly in your template such as (dust syntax):

{?feature-feature1}
MY HIDDDEN CODE
{/feature-feature1}
 

It also provides a string of class names you can insert into your <body> (dust syntax):

<body class="{featureClasses}">

The output prepends feature- to the classname, so you might see something like <body class="feature-feature1"> with the config above. Only enabled features show up in the string.

This route is only available when the feature flag is enabled. Otherwise the user would see a server error page.

var neff = require("neff");
app.get("/myhidden/route", neff.limit("feature1"), function(reqres) {
   res.send("You have found feature1!");
});

Make sure your features are declared on your DOM like so:

<body class="feature-feature1 feature-feature2">

Once you've done that you can take advantage of the flags in 2 ways.

/* Create a block that's hidden by default */
.my-cool-block {
    display: none;
}
 
/* Display that block when your flag is present */
.feature-feature1 .my-cool-block {
    display: block;
}
define(["neff"], function(neff) {
    if (neff.isEnabled("feature1")) {
        /* .. */
    }
});

Inspired heavily by https://npmjs.org/package/feature-gateway.