{"id":17825,"library":"mware","title":"mware Middleware Stack Creator","description":"mware is a lightweight utility designed to create and manage sequential middleware stacks, inspired by patterns found in frameworks like Connect. It provides a simple API (`use` and `run`) to define a series of functions that process a shared context and can either proceed to the next middleware, halt the stack with a success signal, or terminate it by reporting an error. The current stable version is 1.0.1. However, the project's copyright date of 2016 and the nature of its last fix suggest it is largely unmaintained. Its key differentiator is its minimalism, offering a core middleware pattern without the overhead or specific request/response abstractions typical of larger web frameworks, making it suitable for generic processing pipelines in both Node.js and browser environments.","status":"abandoned","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/tur-nr/node-mware","tags":["javascript","middleware","use","next"],"install":[{"cmd":"npm install mware","lang":"bash","label":"npm"},{"cmd":"yarn add mware","lang":"bash","label":"yarn"},{"cmd":"pnpm add mware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary export is a default function that returns an mware instance.","wrong":"import { mware } from 'mware';","symbol":"mware","correct":"import mware from 'mware';"},{"note":"use and run are methods of the instance returned by calling the default mware export, not direct named exports.","wrong":"import { use, run } from 'mware';","symbol":"mware instance methods","correct":"const { use, run } = mware();"},{"note":"For CommonJS environments, the module exports a default function directly.","wrong":"const { mware } = require('mware');","symbol":"mware (CommonJS)","correct":"const mware = require('mware');"}],"quickstart":{"code":"import mware from 'mware';\n\nconst { use, run } = mware();\n\n// Add middleware functions\nuse((ctx, next) => {\n    console.log('Middleware 1: Processing context', ctx);\n    // Modify context or perform async operations\n    setTimeout(() => next(), 100);\n});\n\nuse((ctx, next) => {\n    console.log('Middleware 2: Further processing', ctx);\n    if (ctx.shouldStop) {\n        console.log('Middleware 2: Stopping stack early.');\n        return next(null, 'Stopped Early'); // Stop the stack with a result\n    }\n    return next(); // Proceed to the next middleware\n});\n\nuse((ctx, next) => {\n    console.log('Middleware 3: This might not run if stopped early.');\n    // Simulate an error condition\n    if (ctx.fail) {\n        return next(new Error('Simulated error in middleware 3')); // Stop and report error\n    }\n    next();\n});\n\n// Run the stack with an initial context\nconst context = { value: 42, shouldStop: false, fail: false };\nrun([context], (err, result) => {\n    if (err) {\n        console.error('Stack completed with error:', err.message);\n    } else {\n        console.log('Stack completed successfully. Result:', result || 'No explicit result');\n    }\n    console.log('Final context state:', context);\n});","lang":"javascript","description":"This example demonstrates how to initialize `mware`, add multiple asynchronous middleware functions, and run the stack with a context. It shows how middleware can modify the context, stop the stack early with a result, or terminate with an error."},"warnings":[{"fix":"Evaluate for alternatives if long-term maintenance, security, or feature development is a concern, or consider forking for internal maintenance.","message":"The `mware` project appears to be unmaintained. The latest copyright date in the README is 2016, and version 1.0.1 primarily includes a bug fix, indicating a lack of recent active development or new features. Users should be aware there might not be future updates or security patches.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always pass errors to the `next` function (e.g., `return next(new Error('...'))`) to ensure they are properly caught by the `done` callback.","message":"Error handling in `mware` middleware functions is done by calling `next(new Error())` rather than `throw new Error()`. Throwing an error within a middleware function will bypass the `done` callback and might lead to unhandled promise rejections or uncaught exceptions, depending on the surrounding execution environment.","severity":"gotcha","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":"You must first call the `mware` function to get an instance. Correct: `const { use, run } = mware();`","cause":"Attempting to call `.use()` or `.run()` directly on the `mware` import instead of an `mware` instance.","error":"TypeError: Cannot read properties of undefined (reading 'use')"},{"fix":"Ensure your middleware function correctly accepts `(ctx, next)` as arguments, or however you've chosen to name your context and next callback.","cause":"Middleware function arguments are incorrectly destructured or not provided, leading to `next` being undefined.","error":"Error: next is not a function"},{"fix":"Every middleware function must eventually call `next()` (or `return next(null, result)`/`return next(error)`) to ensure control flow proceeds or terminates correctly.","cause":"A middleware function failed to call `next()` (or `return next()`), causing the stack to hang or stop without reporting completion to the `done` callback.","error":"Middleware stack stopped unexpectedly / Stack never completes"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}