{"id":16976,"library":"composable-middleware","title":"Composable Middleware","description":"Composable Middleware allows developers to treat a sequence of Connect, Flatiron/Union, or hybrid middleware functions as a single, unified middleware function. The package, currently at version 0.3.1, is explicitly marked as abandoned and no longer actively maintained. Its core differentiation lies in its minimal overhead design, focusing solely on function composition without built-in support for URL routing, path mounting, or comprehensive error handling (like 404/500 responses), which are left to the parent framework. It identifies middleware types based on function arity (e.g., `(req,res,next)` for Connect normal middleware, `(err,req,res,next)` for error handling). Given its abandoned status, there is no active release cadence, and users are encouraged to consider maintained forks or alternative solutions.","status":"abandoned","version":"0.3.1","language":"javascript","source_language":"en","source_url":"git://github.com/randymized/composable-middleware","tags":["javascript"],"install":[{"cmd":"npm install composable-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add composable-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add composable-middleware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. Direct ESM imports will fail. You may need a CJS interop layer for modern ESM projects.","wrong":"import composable_middleware from 'composable-middleware';","symbol":"composable_middleware","correct":"const composable_middleware = require('composable-middleware');"},{"note":"The `use` method is a member of the object returned by the main export, not a named export itself. It's chained after invoking the default export.","wrong":"import { use } from 'composable-middleware';","symbol":"composable_middleware().use","correct":"const mw = require('composable-middleware')().use(logger);"}],"quickstart":{"code":"const connect = require('connect');\nconst composable_middleware = require('composable-middleware');\n\n// Mock connect middleware for demonstration\nconst logger = (req, res, next) => {\n  console.log(`${req.method} ${req.url}`);\n  next();\n};\n\nconst greet = (req, res, next) => {\n  res.setHeader('Content-Type', 'text/plain');\n  res.end('Hello from composed middleware!\\n');\n  next(); // Even though we end, pass to next for completion or logging\n};\n\nconst finalHandler = (req, res) => {\n  if (!res.headersSent) {\n    res.statusCode = 404;\n    res.end('Not Found\\n');\n  }\n};\n\n// Compose middleware steps\nconst composedMw = composable_middleware(logger, greet);\n\n// Create a Connect app and use the composed middleware\nconst app = connect();\napp.use(composedMw);\napp.use(finalHandler);\n\nconst PORT = process.env.PORT ?? 3000;\napp.listen(PORT, () => {\n  console.log(`Server running on http://localhost:${PORT}`);\n  console.log('Try accessing http://localhost:3000/');\n});","lang":"javascript","description":"Demonstrates how to compose multiple middleware functions into a single unit using `composable-middleware` and integrate it into a `connect` application. It includes basic logging and a response."},"warnings":[{"fix":"Migrate to a maintained fork (e.g., `ineentho/composable-middleware`) or an alternative middleware composition library. Assess the risks of continued use.","message":"This package is explicitly marked as 'Abandoned' by its maintainers. It is no longer actively developed or supported, which means no new features, bug fixes, or security patches will be released. Using it in production carries significant risk.","severity":"breaking","affected_versions":">=0.3.1"},{"fix":"Use CommonJS `require()` syntax: `const composable_middleware = require('composable-middleware');`. For ESM projects, consider dynamic `import()` or a build step to transpile.","message":"The package is CommonJS-only and does not support native ES Modules (ESM) `import` statements directly. Attempting to use `import` without a CJS interop layer will result in errors.","severity":"gotcha","affected_versions":">=0.3.1"},{"fix":"Implement explicit routing middleware (e.g., `express.Router()`) before or after your composed middleware, and ensure a final middleware handles 404/500 errors if the request reaches the end of the stack without a response.","message":"Composable Middleware intentionally does not handle routing, path mounting, or default error responses (like 404 Not Found or 500 Internal Server Error). Developers must provide their own 'finalware' or rely on the overarching framework for these concerns.","severity":"gotcha","affected_versions":">=0.3.1"},{"fix":"Thoroughly test on your target Node.js version. Be aware that certain Node.js APIs might have changed behavior or been deprecated since the package's last update.","message":"The package targets Node.js versions `>=0.8.0`. While it might run on newer Node.js versions, it has not been tested or updated for modern Node.js APIs or performance optimizations. Compatibility issues or subtle bugs may arise.","severity":"gotcha","affected_versions":">=0.3.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure you are using `const composable_middleware = require('composable-middleware');` for CommonJS projects or if dynamically importing in ESM.","cause":"Attempting to use `composable_middleware` as a function when it was imported incorrectly, likely as a named export in an ESM context, or without a `require` call.","error":"TypeError: composable_middleware is not a function"},{"fix":"If in an ESM module, you must use dynamic import `const composable_middleware = await import('composable-middleware');` or refactor your project to use CommonJS where this package is needed. The `composable-middleware` package itself is CommonJS.","cause":"You are attempting to `require()` an ESM module, or more likely, you are in an ESM context and attempting to `import` this CJS-only package directly without interop.","error":"ERR_REQUIRE_ESM"},{"fix":"Verify the package is installed and `require()` is correct. Ensure you invoke the main export to get an instance before calling `.use()`: `const mw = composable_middleware().use(someMiddleware);`","cause":"This error often occurs if `composable_middleware` itself is `undefined` because `require('composable-middleware')` failed, or if you tried `composable_middleware.use()` directly without first invoking `composable_middleware()` to get an instance.","error":"Cannot read properties of undefined (reading 'use')"}],"ecosystem":"npm","meta_description":null}