XPR-Express.js
This is a Node.js plugin for XPRMNTL feature-client.
It adds the ability to call req.feature
from within an
express.js app. req.feature('expName')
returns the value of the
feature.
Installation
$ npm install xpr-express
API
var featureClient = ;var xprExpress = ;var app = ;var cookieParser = ; featureClient;app;app; app;
xprExpress(config)
-
config.cookieName
is used if no readExps/saveExps are defined. Feature configuration is stored in the user's cookie as needed. -
config.readExps
is a function with the following footprint:Defaults to reading an experiment cookie (
config.cookieName
){// read experiment data from express `req` and `res` or other meansreturn experiments; // see Experiment Format} -
config.saveExps
is a function with the following footprint:Defaults to writing an experiment cookie (
config.cookieName
){// Save experiment configuration to express `res` or other meansreturn; // nothing} -
Experiment Format:
userID: userIDbucket: bucketNumber // 0-99app:userID: userIDbucket: bucketNumber // May be differentstamp: someHash // Used to determine when out-of-datefeatures: {} // Key,value of what is already used for this userdirtyFeatures: {} // Used to override library experiments with `this.features`shared: {} // Same format as `this.app`
feature-client
functionality
Added featureClient.express
is the express middleware that is added to featureClient. It attaches the req.feature() function to thereq
object.req.feature
is a function that determines if a user has an experiment enabled.
Setting features via url
As of v1.0.0, you now have the ability to turn experiments on/off via the url. This is only on a per-user basis, similar to xpr-toggle.
Example
[appUrl]/[path]/?xpr.featName1=true
- Sets feature "featName1" to true
[appUrl]/[path]/?xpr.featName1=false&featName=true
- Sets feature "featName1" to false and "featName2" to true
This also allows you to enable features that normally would not show up in the list (secret features).
FAQ
- The default read/write methods are not working.
- Make sure you are using
express.cookieParser
beforefeatureClient.express
. This is not done for you in case you do your own state lookups.