A small package to implement middleware pattern. This package implements the middleware pattern similar to how express does. You can register global middlewares or event specific middlewares. Refer to Usage Guide for information on how to use.
Installation
- Npm:
npm i create-middleware
- Yarn:
yarn add create-middleware
Usage Guide
middlewares // registering global middlewaresmiddlewares // registering event specific middlewares middlewares // this will execute global middlewares and event specific middlewares in order they were attachedAll the middlewares will recieve the arguments and next as the last argument
To create a new set of middlewares in a different context
const middlewares =
An example of the middleware function
{ logger await } { try await catche // handle error here }
Typically error handler middleware would registered at the beginning globally for it to catch all errors propagating from the middlewares.
Note: All middlewares should be async functions and every next call should be awaited for this feature to work correctly