{"id":18001,"library":"ware","title":"Ware Middleware Composer","description":"Ware is a lightweight JavaScript library designed to easily create and manage a middleware layer for applications. It provides a simple API for composing synchronous, asynchronous, and generator functions into a sequential processing pipeline. The package's current stable version is 1.3.0, released in May 2015. Due to its age, development is no longer active, and the library is considered abandoned. It predates modern `async/await` syntax, relying instead on Node.js's older generator-based asynchronous patterns and explicit `next()` calls for flow control. Its primary differentiator was its simplicity and ability to handle various function types for request/response processing, similar to frameworks like Express but without the opinionated structure, allowing for flexible custom middleware stacks.","status":"abandoned","version":"1.3.0","language":"javascript","source_language":"en","source_url":"git://github.com/segmentio/ware","tags":["javascript","compose","connect","express","layer","middleware"],"install":[{"cmd":"npm install ware","lang":"bash","label":"npm"},{"cmd":"yarn add ware","lang":"bash","label":"yarn"},{"cmd":"pnpm add ware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Ware is a CommonJS module and does not support ES Modules directly. Use `require()` to import.","wrong":"import ware from 'ware'","symbol":"ware","correct":"const ware = require('ware')"},{"note":"The primary `ware` export is a function that creates a new middleware instance; there is no named `Ware` class to import.","wrong":"import { Ware } from 'ware'","symbol":"WareInstance","correct":"const middleware = ware()"}],"quickstart":{"code":"const ware = require('ware');\n\nconst myMiddleware = ware()\n  .use(function (ctx, next) {\n    ctx.log = [];\n    ctx.log.push('Middleware 1: Before next()');\n    next();\n    ctx.log.push('Middleware 1: After next()');\n  })\n  .use(function (ctx, next) {\n    return new Promise(resolve => {\n      setTimeout(() => {\n        ctx.log.push('Middleware 2: Async operation');\n        next();\n        resolve();\n      }, 50);\n    });\n  })\n  .use(function (ctx) {\n    ctx.log.push('Middleware 3: Final step');\n    ctx.result = 'Processed';\n  });\n\nconst context = {};\nmyMiddleware.run(context, function (err, finalContext) {\n  if (err) {\n    console.error('Error in middleware chain:', err);\n  } else {\n    console.log('Final Context:', finalContext);\n    console.log('Execution Log:', finalContext.log);\n    // Expected output for log:\n    // [\n    //   'Middleware 1: Before next()',\n    //   'Middleware 2: Async operation',\n    //   'Middleware 3: Final step',\n    //   'Middleware 1: After next()'\n    // ]\n  }\n});","lang":"javascript","description":"This example demonstrates chaining synchronous and asynchronous middleware functions, showing execution flow and context modification."},"warnings":[{"fix":"For new projects, consider modern middleware solutions that natively support `async/await` or robust Promise-based composition. If using `ware`, wrap `async/await` logic in explicit Promises or use callback-style asynchronous functions.","message":"The package has not been updated since 2015 (version 1.3.0) and uses older Node.js patterns like generator functions. It does not natively support modern `async/await` syntax, which might lead to unexpected behavior or require manual Promise wrapping for asynchronous middleware.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always ensure that each middleware function either calls `next()` (for synchronous or callback-based asynchronous functions) or returns a Promise that resolves (for Promise-based asynchronous functions) to allow the chain to continue.","message":"Middleware functions are expected to call `next()` to pass control to the next function in the chain. Failing to call `next()` (or resolve a Promise in an async function) will halt the middleware execution prematurely, potentially leaving requests hanging or state unupdated.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"In an ES Modules environment, you must use `const ware = require('ware')` after installing a CommonJS interop loader or configure your bundler to handle CommonJS modules.","message":"Ware is a CommonJS module and does not natively support ES Modules (`import`/`export`). Attempting to `import ware from 'ware'` in an ESM context will result in a runtime error.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Change the import statement to `const ware = require('ware');` as it is a CommonJS module.","cause":"Attempting to `import { ware } from 'ware'` or `import Ware from 'ware'` in an ES Module context.","error":"TypeError: ware is not a function"},{"fix":"Review the problematic middleware function to ensure `next()` is called exactly once. This often happens in conditional logic or error handling where `next()` might be called in multiple branches.","cause":"A middleware function is calling `next()` more than once, which can lead to unexpected behavior or errors in the middleware chain.","error":"Error: next() called multiple times"},{"fix":"Inspect the last executing middleware function. Ensure that `next()` is called for synchronous operations, or that a Promise is returned and resolved for asynchronous operations.","cause":"A middleware function failed to call `next()` or resolve its asynchronous operation, causing the middleware chain to stop.","error":"Application hangs or does not proceed past a certain middleware"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}