![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@aldojs/middleware
Advanced tools
A middleware dispatcher and composer for Node.js applications. It provides a clean way to register and invoke a chain of middleware functions.
npm add @aldojs/middleware
To create a new Dispatcher
instance, you may use createDispatcher
utility:
let { createDispatcher } = require('@aldojs/middleware')
let dispatcher = createDispatcher()
Registering middlewares can be done using Dispatcher::use
method
dispatcher.use(function middleware () { return 123 })
To dispatch some input data to the middleware chain, and await the result, you may use the Dispatcher::dispatch
method
let result = await dispatcher.dispatch({ input: 'foobar' })
Dispatcher::dispatch
accepts any input, not only objects.
Each middleware could return any output value including promises.
Whether a middleware runs before or after a downstream middlewares depends on the middleware itself. For example, the following middleware would perform some task before the others
dispatcher.use((input, next) => {
// Perform task
return next()
})
However, this middleware would perform its task after the input is handled by the following middlewares
dispatcher.use(async (input, next) => {
let result = await next()
// Perform the task
return result
})
Composing multiple middleware to make a single handler is easy using the compose
utility:
const { compose } = require('@aldojs/middleware')
let middleware = compose([
someMiddleware,
AnotherMiddleware,
WhyNotAThirdMiddleware
])
FAQs
Middleware disptacher and composer
We found that @aldojs/middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.