Feature Gateway
Simple, memory and JS based feature testing with express support.
Usage
Simple usage:
flags.js
moduleexports = { return userbeta; } { return userid % 10 === 0; }
app.js
'use strict'; var flags = ;var features = flags; var user = beta: true ; // usually from a database if // show beta features
Usage with express routes
The feature gateway can be used with express to block or grant access to particular routes:
flags.js
moduleexports = { // also recieves res & next return reqsessionuserbeta; // content set from some other middleware } { return reqsessionuserid % 10 === 0; }
routes.js
app; app;
Logging
You can attach a logger, and you'll get the data about the feature test:
var features = flags; features { console; console; console;}
Examples
Templating
This is an example of how we're using the features in our handlebar templates (as well as routes and general code):
'use strict';var hbs = features = ; /** * usage: * * {{feature user "alpha"}}<!-- here be the new stuff -->{{/feature}} */ hbs; moduleexports = hbs;
AB testing
The following is an example of how to use the feature gateway to give 50% of users (based on IP address) a feature:
{ // takes the last part of an IP (n.n.n.last-part) and returns as number return reqheaders'x-real-ip' || reqip || '0.0' * 1;} { var ip = ; return ip / 256 <= n / 100;} var features = { // request is the express request object - passed in via our routing OR handlebars feature flags // note that now 50% can easily be tweaked to 10% or even 100% return ; };
Now my code can use fooFeature
test and 50% of visitors will get the feature to allow me to perform real A/B testing.