{"id":17476,"library":"stacked","title":"Stacked Middleware Bundler","description":"Stacked is a stand-alone, lightweight, and zero-dependency utility for bundling multiple middleware functions into a single, cohesive stack. Inspired by `connect`'s middleware infrastructure, it provides a `use` and `mount` API for composing HTTP middleware. As of its last published version, 1.1.1, the package has not seen updates since April 2017, indicating it is no longer actively maintained. Its key differentiator lies in its minimalist design, offering core middleware stacking functionality without the overhead or additional features found in more comprehensive frameworks. It is suitable for projects requiring a simple, independent middleware composition tool, particularly in environments compatible with its older CommonJS module format.","status":"abandoned","version":"1.1.1","language":"javascript","source_language":"en","source_url":"http://github.com/fgnass/stacked","tags":["javascript","connect","middleware","stack"],"install":[{"cmd":"npm install stacked","lang":"bash","label":"npm"},{"cmd":"yarn add stacked","lang":"bash","label":"yarn"},{"cmd":"pnpm add stacked","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. While `import stacked from 'stacked'` might work in some ESM contexts with transpilation or specific Node.js loader configurations, the native and most reliable way is `require()`.","wrong":"import stacked from 'stacked'","symbol":"stacked","correct":"const stacked = require('stacked')"},{"note":"The package provides a default export (the `stacked` function), not named exports. Attempting to use named imports will result in `undefined`.","wrong":"import { stacked } from 'stacked'","symbol":"stacked (with named exports)","correct":"const stacked = require('stacked')"}],"quickstart":{"code":"const stacked = require('stacked');\nconst http = require('http');\n\n/**\n * A simple logging middleware.\n */\nfunction loggerMiddleware(req, res, next) {\n  console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}`);\n  next();\n}\n\n/**\n * A middleware that adds a custom header.\n */\nfunction headerMiddleware(req, res, next) {\n  res.setHeader('X-Powered-By', 'Stacked');\n  next();\n}\n\n/**\n * A specific middleware for a mounted path.\n */\nfunction mountedPathMiddleware(req, res, next) {\n  // req.url is stripped to the mount point here\n  console.log('Mounted path URL:', req.url, 'Original URL:', req.originalUrl);\n  res.end('Hello from mounted path!');\n}\n\n// Create the stacked middleware instance\nconst app = stacked()\n  .use(loggerMiddleware)\n  .use(headerMiddleware)\n  .mount('/api', mountedPathMiddleware)\n  .use((req, res, next) => {\n    // This middleware only runs if the above .mount('/api') did not handle the request\n    res.statusCode = 200;\n    res.setHeader('Content-Type', 'text/plain');\n    res.end('Hello from root!');\n  });\n\n// Create a Node.js HTTP server and use the stacked app as its request listener\nconst server = http.createServer(app);\n\nconst port = 3000;\nserver.listen(port, () => {\n  console.log(`Server listening on http://localhost:${port}`);\n  console.log('Try visiting:');\n  console.log(`- http://localhost:${port}/`);\n  console.log(`- http://localhost:${port}/api/data`);\n});","lang":"javascript","description":"This quickstart demonstrates how to initialize `stacked`, register multiple global middleware functions using `.use()`, and mount a specific middleware to a path using `.mount()`. It sets up a basic HTTP server to showcase how `stacked` handles incoming requests through the defined middleware chain, including path-specific logic."},"warnings":[{"fix":"Consider migrating to actively maintained middleware frameworks like Express.js or Koa.js, or re-implementing the middleware stacking logic using native Node.js HTTP modules for better long-term support and security.","message":"The `stacked` package is effectively abandoned, with no updates since April 2017. This means it lacks support for modern JavaScript features (like native ESM) and will not receive security patches, bug fixes, or performance improvements. Integrating it into modern Node.js environments may lead to compatibility issues or require specific polyfills/transpilation configurations.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"In an ESM project, if `stacked` is indispensable, use `const stacked = await import('stacked');` for asynchronous loading, or ensure your build system properly transpiles CommonJS modules. For new projects, prefer ESM-compatible middleware solutions.","message":"Being a CommonJS-only package, `stacked` does not natively support ECMAScript Modules (ESM). Directly `import stacked from 'stacked'` in an ESM project will likely fail or require Node.js `--experimental-json-modules` flag, `esModuleInterop` in TypeScript, or a bundler to resolve correctly. Its usage with modern tooling that defaults to ESM might be problematic.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `req.originalUrl` when the full request path is needed within mounted middleware. Be mindful that `req.url` inside a mounted middleware will be the path *relative* to the mount point, not the full path.","message":"The `mount` method in `stacked` modifies `req.url` to be relative to the mount point, and adds `req.originalUrl` for the full, original URL. This behavior might differ from other middleware frameworks (e.g., Express.js) where `req.url` typically remains relative to the mount point but `req.baseUrl` or `req.path` might be used differently. Unawareness of this can lead to incorrect path handling.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure `const stacked = require('stacked');` is used in CommonJS environments. In ESM, if you must use it, `const { default: stacked } = await import('stacked');` might work, but it's not guaranteed without specific configuration.","cause":"Attempting to use `stacked` as a function immediately after an incorrect CommonJS `require` or an ESM `import` that didn't resolve the default export correctly.","error":"TypeError: stacked is not a function"},{"fix":"If your project is CommonJS, stick to `const stacked = require('stacked');`. If your project is ESM, either configure Node.js and TypeScript to correctly handle CommonJS interop, or use dynamic import `const { default: stacked } = await import('stacked');`.","cause":"Attempting to use `import stacked from 'stacked'` in a Node.js project that is configured as CommonJS (missing `\"type\": \"module\"` in `package.json` or not using `.mjs` file extension), as `stacked` itself is a CommonJS module, but the attempting *importer* is trying to use ESM syntax.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null}