middleware-io is a lightweight, zero-dependency library for composing promise-based middleware in JavaScript and TypeScript applications. It provides a `compose` function similar to `koa-compose` and a `Composer` class for building middleware chains with various utility 'snippets' like lazy loading, forking, and concurrency control. The library is written in TypeScript, ensuring type safety and a robust development experience. Currently at version 2.8.1, its release cadence has been irregular since its active development phase around 2019-2021, with the latest significant changes related to `exports` in `package.json` for modern module resolution. Key differentiators include its self-sufficiency (zero dependencies), native ESM support, and a rich set of built-in middleware snippets.
npm install middleware-ioVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic promise-based middleware composition, context modification, and asynchronous flow control using `compose`.
Upgrade your Node.js runtime to version 12.0.0 or newer. Check your `engines` field in `package.json`.
Change `import middlewareIO from 'middleware-io'` to `import { compose } from 'middleware-io'` and refactor code using `MiddlewareStatus`.Review calls to affected snippets and `Composer` instantiation, updating argument order and providing a generic type for `Composer` (e.g., `new Composer<MyContext>()`).
Always use named `import` statements (e.g., `import { compose } from 'middleware-io'`). If using CommonJS, ensure your environment supports `exports` map resolution or consider using dynamic `import()` for ESM-only packages.Review your middleware logic, especially around `next()` calls, to ensure compatibility with `koa-compose`'s single `next()` invocation policy. Update `Composer` instantiation with generics where appropriate.
Ensure your project is set up for ES Modules (`"type": "module"` in `package.json`) and use `import { Symbol } from 'middleware-io'` syntax. Alternatively, use dynamic `import()`: `const { Symbol } = await import('middleware-io')`.Verify your `tsconfig.json` `module` setting (e.g., `"ESNext"` or `"NodeNext"`) and `moduleResolution`. Ensure you are using named imports: `import { compose } from 'middleware-io'`.Explicitly provide a generic type to `compose` or `Composer` that matches your context object, e.g., `compose<MyContext>(...)` or `new Composer<MyContext>()`.
No dependency data recorded yet.