# toisu-middleware-runner

> The core middleware runner for Toisu!

Latest version **3.0.2** (published 2021-04-27) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install toisu-middleware-runner
pnpm add toisu-middleware-runner
yarn add toisu-middleware-runner
bun add toisu-middleware-runner
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2021-04-27 |
| First published | 2015-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mark S. Everitt |
| Maintainers | qubyte |
| Keywords | toisu, middleware |

## Links

- npm: https://www.npmjs.com/package/toisu-middleware-runner
- Repository: https://github.com/qubyte/toisu-middleware-runner
- Homepage: https://github.com/qubyte/toisu-middleware-runner#readme
- Issues: https://github.com/qubyte/toisu-middleware-runner/issues
- npm.io page: https://npm.io/package/toisu-middleware-runner

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2021-04-27
- 2.0.2 — 2021-04-27
- 3.0.0 — 2021-04-26
- 2.0.1 — 2019-02-13
- 2.0.0 — 2017-02-22
- 1.0.4 — 2016-08-30
- 1.0.3 — 2016-03-29
- 1.0.2 — 2015-12-20
- 1.0.0 — 2015-08-29

## README

# Toisu! middleware runner

For Node.js versions less than 14 please use the 2.x line of releases.

Toisu! runs middlewares in sequence, waiting for promises from middlwares to resolve (when promises
are returned) before continuing to the next. This module contains a function which does this
sequential middleware execution. This logic has been placed in its own module since both `toisu` and
`toisu-router` use it. Other modules intended to work with Toisu! might also find it useful.

## usage

Middleware may either be a function which runs synchronously, or one that returns a promise. A
mixture of synchronous and asynchronous functions may be used. Note though, that the runner returns
a promise and will always resolve asynchronously.

With plain old ES2015:
```javascript
import runner from 'toisu-middleware-runner';

// context will be used as the `this` value for middlewares.
runner.call(context, req, res, middlewares)
  .then(() => {
    // Run when either all middlewares have been used, or one called `res.end()`.
  })
  .catch(err => {
    // Run when a middleware threw.
  });
```

With async-await:
```javascript
import runner from 'toisu-middleware-runner';

async function example() {
  try {
    await runner.call(context, req, res, middlwares);
  } catch (e) {
    // Handle errors.
    return;
  }

  // When either all middlewares have been used, or one called `res.end()`.
}
```

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