unleash-client that helps persisting feature toggle results over Express.js
const { initialize } = require('unleash-client');
const unleash = initialize(...);
const { UnleashExpress } = require('unleash-express');
const unleashExpress = new UnleashExpress(unleash, options);
Available options:
cookieName
(string): The name of the cookie to persist the result values of each feature toggle. Defaults to 'unleash'cookieOptions
(object): Additionl options for the cookie likeexpires
ormaxAge
. No default.
app.use(cookieParser());
app.use(unleashExpress.middleware()); // This will allow reading/setting the cookies
Ask unleash-client
for the value of a feature as usual by using experiment
.
// In your feature.controller.js
req.unleash.experiment('feature', ...);
You can also check alternatives or features that are enabled by using isEnabled
.
// In your controller
req.unleash.isEnabled('alternative');
Peek the persisted results:
req.unleash.results['feature']; // Variant object or null
Inspired by fflip-express