README
Modern middleware on Promise
📖 Documentation |
---|
Features
- Working with async/await
- Zero dependencies
- Native Promise
- Flexible
- Snippets
- Typings
Installation
Node.js 12.0.0 or newer is required
Yarn
Recommended
yarn add middleware-io
NPM
npm install middleware-io --save
Usage
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);