Socket
Socket
Sign inDemoInstall

middleware-io

Package Overview
Dependencies
0
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    middleware-io

Modern middleware with promises and status


Version published
Maintainers
1
Install size
36.6 kB
Created

Readme

Source

Build Status NPM version NPM downloads

Middleware-IO - Modern middleware on Promise

📖 Documentation

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
  4. Powerful. Supports following additional features:
    • The library has enough built-in snippets;
    • The middleware chain builder;

Installation

Node.js 12.0.0 or newer is required

  • Using npm (recommended)
    npm i middleware-io
    
  • Using Yarn
    yarn add middleware-io
    
  • Using pnpm
    pnpm add middleware-io
    

Example 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);

Keywords

FAQs

Last updated on 20 Sep 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc