# middleware-io

> Modern middleware with promises and status

Latest version **2.8.1** (published 2022-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install middleware-io
pnpm add middleware-io
yarn add middleware-io
bun add middleware-io
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.8.1 |
| Published | 2022-09-20 |
| First published | 2017-10-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12.0.0 |
| Dependencies | 0 |
| Unpacked size | 36.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Vladlen |
| Maintainers | negezor |
| Keywords | typescript, middleware, compose, ware, promise, async, await, modern, es2015, es6, es7, cjs, esm, js |

## Links

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

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.8.1 (latest) — 2022-09-20
- 2.8.0 — 2021-06-10
- 2.7.0 — 2021-06-10
- 2.6.0 — 2021-03-28
- 2.5.0 — 2020-02-21
- 2.4.0 — 2020-01-20
- 2.3.0 — 2020-01-02
- 2.2.0 — 2020-01-02
- 2.1.0 — 2019-10-06
- 2.0.0 — 2019-06-19
- 1.1.0 — 2019-01-19
- 1.0.0 — 2019-01-14
- 0.0.8 — 2018-09-10
- 0.0.7 — 2018-07-24
- 0.0.6 — 2018-04-11
- … 5 more at https://npm.io/package/middleware-io/versions

## README

<p align="center"><img src="https://raw.githubusercontent.com/negezor/middleware-io/master/logo.svg?sanitize=true"></p>
<p align="center">
<a href="https://github.com/negezor/middleware-io/actions/workflows/tests.yml"><img src="https://img.shields.io/github/workflow/status/negezor/middleware-io/Middleware-IO CI?style=flat-square" alt="Build Status"></a>
<a href="https://www.npmjs.com/package/middleware-io"><img src="https://img.shields.io/npm/v/middleware-io.svg?style=flat-square" alt="NPM version"></a>
<a href="https://www.npmjs.com/package/middleware-io"><img src="https://img.shields.io/npm/dt/middleware-io.svg?style=flat-square" alt="NPM downloads"></a>
</p>

> **Middleware-IO** - Modern middleware on Promise

| 📖 [Documentation](docs/) |
|---------------------------|

## Features

1. **Self-Sufficient.** The library has zero dependencies.
2. **Reliable.** The library is written in **TypeScript** and covered by tests.
3. **Modern.** The library comes with native ESM support
3. **Powerful.** Supports following additional features:
	- The library has enough built-in snippets;
	- The middleware chain builder;

## Installation
> **[Node.js](https://nodejs.org/) 12.0.0 or newer is required**

- **Using `npm`** (recommended)
	```shell
	npm i middleware-io
	```
- **Using `Yarn`**
  ```shell
  yarn add middleware-io
  ```
- **Using `pnpm`**
  ```shell
  pnpm add middleware-io
  ```

## Example usage

```js
import { compose } from 'middleware-io';

const composedMiddleware = compose([
	async (context, next) => {
		// Step 1

		await next();

		// Step 4

		// Print the current date from the next middleware
		console.log(context.now);
	},
	async (context, next) => {
		// Step 2

		context.now = Date.now();

		await next();

		// Step 3
	}
]);

composedMiddleware({}, () => { /* Last handler (next) */ })
	.then(() => {
		console.log('Middleware finished work');
	})
	.catch(console.error);
```

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