# node-ab-decider

> [![CircleCI](https://circleci.com/gh/zapaiamarce/node-ab-decider.svg?style=svg)](https://circleci.com/gh/zapaiamarce/node-ab-decider)

Latest version **0.0.20** (published 2019-06-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install node-ab-decider
pnpm add node-ab-decider
yarn add node-ab-decider
bun add node-ab-decider
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.20 |
| Published | 2019-06-07 |
| First published | 2018-12-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 153.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | qzapaia |

## Links

- npm: https://www.npmjs.com/package/node-ab-decider
- npm.io page: https://npm.io/package/node-ab-decider

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [nocache](https://npm.io/package/nocache.md) ^2.1.0
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.4
- [express-http-proxy](https://npm.io/package/express-http-proxy.md) ^1.5.1

## Recent versions

- 0.0.20 (latest) — 2019-06-07
- 0.0.19 — 2019-03-13
- 0.0.18 — 2019-03-09
- 0.0.17 — 2019-03-09
- 0.0.16 — 2019-02-28
- 0.0.15 — 2019-02-26
- 0.0.14 — 2019-02-11
- 0.0.13 — 2019-01-29
- 0.0.12 — 2019-01-28
- 0.0.11 — 2019-01-28
- 0.0.10 — 2018-12-19
- 0.0.9 — 2018-12-17
- 0.0.8 — 2018-12-14
- 0.0.7 — 2018-12-14
- 0.0.6 — 2018-12-14
- … 5 more at https://npm.io/package/node-ab-decider/versions

## README

[![CircleCI](https://circleci.com/gh/zapaiamarce/node-ab-decider.svg?style=svg)](https://circleci.com/gh/zapaiamarce/node-ab-decider)

## Setup

```sh
npm install node-ab-decider
```

## Use

```js
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.


## With Express

```js
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.

# Middleware options

### maxAge
Expiration (in milliseconds) of the cookie

### cookieName
Name of the cookie used to save the choosen exp

### skip
Skip this middleware. Useful in dev mode.

### hash
Hash added to the cookie. It is something like a version.

### sendHeaderToChild
If false it avoids to send "ab-decider-child" header to the proxied endpoint

### https
Force https to children

### headers
Headers to include in every response

---
_Source: https://npm.io/package/node-ab-decider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
