JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2063
  • Score
    100M100P100Q113063F
  • License MIT

Modern middleware with promises and status

Package Exports

  • middleware-io
  • middleware-io/lib/index

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (middleware-io) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status NPM version NPM downloads

Modern middleware on Promise

📖 Documentation

Features

  • Working with async/await
  • Zero dependencies
  • Native Promise
  • Flexible
  • Snippets
  • Typings

Installation

Node.js 10.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({}, context => { /* Last middleware */ })
    .then(() => {
        console.log('Middleware finished work');
    })
    .catch(console.error);