Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/negezor/middleware-io
⛓️ Modern middleware with promises
https://github.com/negezor/middleware-io
middleware promise
Last synced: about 2 months ago
JSON representation
⛓️ Modern middleware with promises
- Host: GitHub
- URL: https://github.com/negezor/middleware-io
- Owner: negezor
- License: mit
- Created: 2017-10-29T10:29:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T12:57:01.000Z (8 months ago)
- Last Synced: 2024-12-10T05:42:07.591Z (about 2 months ago)
- Topics: middleware, promise
- Language: TypeScript
- Homepage:
- Size: 1.31 MB
- Stars: 20
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
> **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 1await next();
// Step 4
// Print the current date from the next middleware
console.log(context.now);
},
async (context, next) => {
// Step 2context.now = Date.now();
await next();
// Step 3
}
]);composedMiddleware({}, () => { /* Last handler (next) */ })
.then(() => {
console.log('Middleware finished work');
})
.catch(console.error);
```