Co-compose is a lightweight, framework-agnostic middleware composition library for JavaScript and TypeScript applications, inspired by patterns found in Koa and AdonisJS. It enables developers to define an array of asynchronous functions (middleware) and execute them sequentially, with explicit control flow via a `next()` function. The current stable version is 7.0.3, which primarily includes dependency updates and minor fixes. Major versions, like v7, tend to update Node.js compatibility requirements, with minor and patch releases focusing on performance improvements and dependency hygiene. Key differentiators include its reported high performance (benchmarked against alternatives like `fastseries` and `middie`), flexibility with custom executors for different middleware shapes (e.g., ES6 classes), and a dedicated final handler mechanism. It ships with full TypeScript types, making it suitable for modern typed environments.
npm install co-composeVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic middleware registration and sequential execution using the `Middleware` class, including how to pass context.
Upgrade your Node.js runtime to version 16 or later to maintain compatibility.
Always include `await next()` within your middleware functions, unless the intention is to terminate the chain and prevent further execution.
Carefully review your custom executor implementation to ensure it matches the expected interface and execution requirements of your custom middleware definitions.
Ensure your middleware function correctly accepts `next` as an argument (e.g., `async function (ctx, next) { ... }`) and that `next()` is called as `await next()`.Always declare your middleware functions with the `async` keyword when using `await`, for example: `async function myMiddleware(ctx, next) { await next(); }`.Ensure `co-compose` is installed (`npm install co-compose` or `yarn add co-compose`) and that `Middleware` is imported using `import { Middleware } from 'co-compose'`.No dependency data recorded yet.