{"id":17569,"library":"debug-error-middleware","title":"Debug Error Middleware","description":"debug-error-middleware, currently at version 1.3.0 (last published 7 years ago), provides a development-focused error handling middleware for Express and Koa applications. Its primary function is to display detailed context information, including stack traces and object internals, in the response to failed requests. This is invaluable for debugging during development, offering insights into errors that would typically be suppressed or logged without immediate feedback to the client. A key differentiator is its automatic source map support, making transpiled code errors easier to interpret, though this can be disabled. The package's most critical aspect is its explicit and enforced prevention of use in production environments, as it leaks sensitive system information, making it solely a development utility. Given its last update date, the project appears to be abandoned.","status":"abandoned","version":"1.3.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install debug-error-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add debug-error-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add debug-error-middleware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For Express applications, import the 'express' export from the module. Although the README shows CommonJS `require`, the library primarily uses named exports for framework-specific middleware.","wrong":"const debugExpressMiddleware = require('debug-error-middleware');","symbol":"express","correct":"import { express as debugExpressMiddleware } from 'debug-error-middleware';"},{"note":"For Koa applications, import the 'koa' export from the module. The library exports framework-specific middleware via named exports.","wrong":"const debugKoaMiddleware = require('debug-error-middleware');","symbol":"koa","correct":"import { koa as debugKoaMiddleware } from 'debug-error-middleware';"},{"note":"This package uses CommonJS `require` syntax and named exports (`.express`, `.koa`). Attempting a default ESM import (`import debugMiddleware from 'pkg'`) or a direct `require('pkg')` without specifying the framework export will fail.","wrong":"import debugMiddleware from 'debug-error-middleware';","symbol":"debugMiddleware","correct":"const { express: debugMiddleware } = require('debug-error-middleware');"}],"quickstart":{"code":"import express from 'express';\nimport { express as debugMiddleware } from 'debug-error-middleware';\n\nconst app = express();\n\n// CRITICAL: ONLY enable in development!\nif (process.env.NODE_ENV === 'development' || !process.env.NODE_ENV) {\n  // The debug middleware should be loaded first to catch errors from all other middleware.\n  app.use(debugMiddleware({\n    theme: 'okaidia', // Optional: customize Prism.js theme\n    disabledForXHR: true // Optional: disable for XHR requests\n  }));\n}\n\n// Simulate an API route that throws an error\napp.get('/error', (req, res, next) => {\n  const customError = new Error('Something went wrong during data processing.');\n  customError.statusCode = 400;\n  customError.data = { requestBody: req.body, queryParams: req.query };\n  next(customError);\n});\n\n// A catch-all for routes not found, which will also trigger the error handler\napp.use((req, res, next) => {\n  const notFoundError = new Error(`Cannot ${req.method} ${req.originalUrl}`);\n  notFoundError.statusCode = 404;\n  next(notFoundError);\n});\n\n// Start the server\nconst port = process.env.PORT || 3000;\napp.listen(port, () => {\n  console.log(`Server running on http://localhost:${port} in ${process.env.NODE_ENV || 'development'} mode`);\n  console.log('Access /error to see the debug output in development.');\n});","lang":"javascript","description":"This quickstart demonstrates how to integrate `debug-error-middleware` into an Express application, ensuring it's only active in development and correctly positioned to catch errors."},"warnings":[{"fix":"Ensure the middleware is conditionally loaded based on `NODE_ENV`. The library itself throws an error if `NODE_ENV` is 'production' when it's initialized. Always guard its usage with `if (process.env.NODE_ENV !== 'production') { app.use(debugMiddleware()); }`.","message":"Enabling `debug-error-middleware` in a production environment is a severe security risk. It explicitly exposes sensitive information, including environment variables, stack traces, and internal object details, which attackers could exploit.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For Express, `app.use(debugMiddleware());` should be called before any routes or other middleware that could potentially throw errors. For Koa, ensure it's wrapped in a `try/catch` block within an `app.use` that is added early in the middleware stack.","message":"The middleware must be loaded as one of the *first* middlewares in your application's chain (especially for Express) to ensure it can catch errors from all subsequent middleware and routes. Incorrect placement may result in errors being handled by default Express/Koa handlers or other middlewares.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always set `NODE_ENV` correctly for your deployment environment. For development, `NODE_ENV=development` or unset, and for production, `NODE_ENV=production`.","message":"The library explicitly checks `process.env.NODE_ENV`. If it's set to 'production', the middleware will deliberately throw an error during initialization, preventing accidental deployment in an unsafe configuration.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For new projects, consider actively maintained alternatives like `errorhandler` for Express, which also provides similar debug-focused error handling, or robust custom error-handling middleware patterns tailored for production.","message":"The project appears to be abandoned, with no updates in 7 years. While functional, it may not receive patches for future security vulnerabilities, compatibility issues with newer Node.js versions, or updates for newer Express/Koa features or paradigms (e.g., ESM).","severity":"gotcha","affected_versions":">=1.3.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Ensure `process.env.NODE_ENV` is set to 'development' (or is unset) when running your application locally or in a development environment. Do not deploy this middleware to production.","cause":"The middleware was initialized in an environment where `process.env.NODE_ENV` was set to 'production'. This is a built-in security measure.","error":"Error: debug-error-middleware cannot be loaded when NODE_ENV is 'production'"},{"fix":"Use CommonJS named export destructuring: `const { express: debugMiddleware } = require('debug-error-middleware');` or for Koa: `const { koa: debugMiddleware } = require('debug-error-middleware');` if not using ESM-aware bundlers.","cause":"Attempting to `require` or `import` the module without specifying the `express` or `koa` named export, or using an incorrect import style for CommonJS modules.","error":"TypeError: Cannot read properties of undefined (reading 'express')"},{"fix":"Ensure `debug-error-middleware` is applied as one of the very first middleware functions in your application stack. For Koa, explicit `try/catch` blocks around `await next()` within your error middleware can ensure proper error propagation for async operations.","cause":"Errors are not being caught by `debug-error-middleware`. This often happens if the middleware is placed *after* other routes or middleware that throw errors, or if asynchronous errors in Koa are not properly propagated.","error":"Error: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: X)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}