# express-chaos-middleware

> Put some chaos in your express application

Latest version **1.2.4** (published 2023-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-chaos-middleware
pnpm add express-chaos-middleware
yarn add express-chaos-middleware
bun add express-chaos-middleware
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.4 |
| Published | 2023-04-05 |
| First published | 2021-12-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 2 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | ziggornif |
| Maintainers | ziggornif |
| Keywords | express, chaos, testing |

## Links

- npm: https://www.npmjs.com/package/express-chaos-middleware
- Repository: https://github.com/drouian-m/express-chaos-middleware
- Homepage: https://github.com/drouian-m/express-chaos-middleware#readme
- Issues: https://github.com/drouian-m/express-chaos-middleware/issues
- npm.io page: https://npm.io/package/express-chaos-middleware

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) ^4.3.4
- [seedrandom](https://npm.io/package/seedrandom.md) ^3.0.5

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.2.4 (latest) — 2023-04-05
- 1.2.3 — 2023-04-05
- 1.2.2 — 2023-04-05
- 1.2.1 — 2023-04-05
- 1.2.0 — 2023-04-05
- 1.1.4 — 2022-12-22
- 1.0.0 — 2021-12-20

## README

# express-chaos-middleware

Put some chaos in your express application.

## Description

The aim of this library is to provide simple chaos testing cases for express applications.

## Installation

```sh
npm add express-chaos-middleware
```

## Features

- Requests slowdown : Endpoints can be slowed down randomly 
- Random response error : Endpoints can respond randomly with an error code
- Random exception : Endpoints can throw exceptions randomly
- Seeding : Manage random to replay scenarios

Chaos features have a 10 percent "chance" of being called by default. The percentage can be changed in the configuration object.

## Usage

### Simple usage

```js
const {chaos} = require('express-chaos-middleware');

app.use(chaos())
```

### Use an existing seed

The random seed can be configured in the input object param.

```js
const {chaos} = require('express-chaos-middleware');

app.use(chaos({
  // this seed throw an exception on the first call
  seed: 'uJaK8BUr2084pph',
}))
```

### Advanced usage - Change chaos probability

The probability of chaos can be configured in the input object param.

This parameter is a number value between 0 and 100.

```js
const {chaos} = require('express-chaos-middleware');

app.use(chaos({
  probability: 50,
}))
```

### Advanced usage - Override max delay

The max slowdown delay can be configured in the input object param.

```js
const {chaos} = require('express-chaos-middleware');

app.use(chaos({
  maxDelay: 1000,
}))
```

### Advanced usage - Use custom http error codes array

The http error codes array can be overridden in the input object param.

```js
const {chaos} = require('express-chaos-middleware');

app.use(chaos({
  errCodes: [400, 500],
}))
```

### Advanced usage - Use custom feature list 

The chaos feature list can be overridden in the input object param.

You can for example only use delay and http error codes with the following configuration

All rules are exported in the `Rules` object.

```js
const {chaos} = require('express-chaos-middleware');

app.use(chaos({
  rules: [Rules.DELAY, Rules.HTTPERROR],
}))
```

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