{"id":18541,"library":"meddleware","title":"meddleware","description":"Configuration-based middleware registration for Express.js. Current stable version is 3.0.4. Meddleware allows you to define middleware in a configuration object with options like enabled, priority, route, and module. It supports loading middleware from npm modules or local files, specifying factory methods and arguments, and flow control (parallel, series). Key differentiators include priority-based ordering, route-based activation, and parallel/sequential execution control. The package has been around since Express 4.x and is part of the Kraken.js ecosystem. It is maintained with a focus on production usage.","status":"active","version":"3.0.4","language":"javascript","source_language":"en","source_url":"git://github.com/krakenjs/meddleware","tags":["javascript","express","middleware"],"install":[{"cmd":"npm install meddleware","lang":"bash","label":"npm"},{"cmd":"yarn add meddleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add meddleware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"meddleware is a CommonJS module; dynamic import is not typical. Use require() for now.","wrong":"import meddleware from 'meddleware';","symbol":"meddleware","correct":"const meddleware = require('meddleware');\nconst express = require('express');\nconst app = express();\napp.use(meddleware(config));"},{"note":"The package exports a single function, not a named export.","wrong":"const { meddleware } = require('meddleware');","symbol":"default export","correct":"const meddleware = require('meddleware');\napp.use(meddleware(config));"},{"note":"If using TypeScript with esModuleInterop, you can use default import. Otherwise use require().","wrong":"const meddleware = require('meddleware');","symbol":"TypeScript type import","correct":"import meddleware from 'meddleware';\napp.use(meddleware(config));"}],"quickstart":{"code":"const http = require('http');\nconst express = require('express');\nconst meddleware = require('meddleware');\nconst config = {\n  static: {\n    enabled: true,\n    priority: 20,\n    module: {\n      name: 'serve-static',\n      arguments: ['public']\n    }\n  },\n  security: {\n    enabled: true,\n    priority: 10,\n    module: {\n      name: './lib/security',\n      arguments: [{ maximum: true }]\n    }\n  }\n};\nconst app = express();\napp.use(meddleware(config));\nhttp.createServer(app).listen(8080);","lang":"javascript","description":"Shows basic usage of meddleware to register middleware from configuration with priority, enabled flag, and module arguments."},"warnings":[{"fix":"Explicitly set `enabled: false` for middleware you want disabled, or upgrade to v3 which keeps the same behavior.","message":"In meddleware 2.0.0, the default value for the `enabled` option changed from `false` to `true`. Previously, omitting `enabled` would disable the middleware; now it enables it.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Check if your middleware factory relies on `this` being `null`; if so, update it to handle the new context.","message":"In meddleware 3.0.1, registered middleware factories are now called with a context set to the method owner. Previously, the factory was called with a context of `null`.","severity":"breaking","affected_versions":">=3.0.1"},{"fix":"Consider using an ordered array of middleware definitions if you need strict ordering.","message":"The `priority` option is still used but may be deprecated in future versions in favor of explicit ordering.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Use a JSON preprocessor like shortstop with shortstop-regex, or define config in JavaScript instead of JSON.","message":"When configuring meddleware with JSON files, regex patterns in routes cannot be represented natively. You must use a shortstop handler (e.g., shortstop-regex) to convert strings to RegExp.","severity":"gotcha","affected_versions":">=2.1.0"},{"fix":"If using regex routes, consider the mountpath manually or use string routes.","message":"String paths in `route` are automatically prefixed with any mountpath, but regular expressions are not. This can lead to unexpected behavior when using meddleware under a sub-app.","severity":"gotcha","affected_versions":">=2.1.0"},{"fix":"Set `method` in the config to the exact exported function name you want to use.","message":"The `module.method` option defaults to the current middleware name, and then to the module itself. If your module exports a specific function, you may need to set `method` explicitly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to v3.0.4 or ensure all middleware modules are in the app's node_modules directory.","message":"Meddleware uses `require.resolve()` to find the module. If the module is not in the application's node_modules, it may fail. In v3.0.4, resolution was improved for modules outside the app's node_module.","severity":"gotcha","affected_versions":"<3.0.4"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use `const meddleware = require('meddleware');` or enable esModuleInterop in TypeScript and use `import meddleware from 'meddleware';`","cause":"Importing the module incorrectly, e.g., using default import without esModuleInterop or named destructuring.","error":"TypeError: meddleware is not a function"},{"fix":"Install the module with `npm install some-middleware` and ensure it is in the app's node_modules. For local modules, use a relative path like './lib/some-middleware'.","cause":"The module specified in config 'some-middleware' is not installed or not in the module search path.","error":"Error: Cannot find module 'some-middleware'"},{"fix":"Check the module's exports. Set `method` to the exact exported function name, or omit it if the module itself is the middleware factory.","cause":"The module exported does not have a function matching the `method` name, or the module itself is not a function.","error":"TypeError: middlewareFactory is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}