npm install node-ab-decider
const decider = require('node-ab-decider')
const choosen = "oldVariant"
const experiments = {
variantA: {
weight: 10,
url: "https://exp-a.example.com/"
},
variantB: {
weight: 20,
url: "https://exp-b.example.com/"
}
}
const x = decider(experiments, choosen)
// possible "x" value: {weight: 10, name:"variantA", url: "https://exp-a.example.com/"}
NOTE: If choosen
is present the experiments object
it doesn't run the choosing algorithm. If it's not present it re-run
the process.
var app = require('express')();
const {middleware} = require('node-ab-decider')
const experiments = {
variantA: {
weight: 10,
url: "https://exp-a.example.com/"
},
variantB: {
weight: 20,
url: "https://exp-b.example.com/"
}
}
app.use(middleware(experiments, {
// ...opts
}), (req,res)=>res.send('original'))
app.listen(2323,()=>console.log('running on 2323'))
Same logic but, it uses cookies to get the choosen or set the cookie.
Expiration (in milliseconds) of the cookie
Name of the cookie used to save the choosen exp
Skip this middleware. Useful in dev mode.
Hash added to the cookie. It is something like a version.
If false it avoids to send "ab-decider-child" header to the proxied endpoint
Force https to children
Headers to include in every response