{"library":"stacked","title":"Stacked Middleware Bundler","type":"library","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.","language":"javascript","status":"abandoned","last_verified":"Wed Apr 22","install":{"commands":["npm install stacked"],"cli":null},"imports":["const stacked = require('stacked')","const stacked = require('stacked')"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/fgnass/stacked","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/stacked","openapi_spec":null,"status_page":null,"smithery":null},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}