{"id":17203,"library":"debug-http","title":"Debug HTTP/HTTPS Requests","description":"debug-http is a minimalist Node.js utility designed to intercept and log all outgoing HTTP and HTTPS requests made within an application. It achieves this by patching Node.js's built-in `http` and `https` modules to provide visibility into request details like URL, method, and headers. The package is currently at version 1.1.0 and has not seen updates in nearly a decade, indicating it is no longer actively maintained. Its primary function is a simple, global request handler that outputs request information to the console by default, though it allows for a custom handler function. Due to its age, it exclusively supports CommonJS module loading and does not officially support modern JavaScript features like ESM or TypeScript. Alternatives like `debug` or `request-debug` offer more robust and actively maintained debugging capabilities, especially for specific HTTP client libraries or more granular control over debug output.","status":"abandoned","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/floatdrop/debug-http","tags":["javascript","debug","http","https","requests"],"install":[{"cmd":"npm install debug-http","lang":"bash","label":"npm"},{"cmd":"yarn add debug-http","lang":"bash","label":"yarn"},{"cmd":"pnpm add debug-http","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is primarily CommonJS, but this is the hypothetical ESM import. The default export is the function itself. The CommonJS `require` call directly returns the function, so `require('debug-http').debugHttp` is incorrect.","wrong":"const debugHttp = require('debug-http').debugHttp;","symbol":"debugHttp","correct":"import debugHttp from 'debug-http'"},{"note":"This is the correct and intended CommonJS import for the package, which exports the main function directly.","symbol":"debugHttp","correct":"const debugHttp = require('debug-http');"}],"quickstart":{"code":"const debugHttp = require('debug-http');\nconst http = require('http');\nconst https = require('https');\n\n// Enable HTTP/HTTPS request debugging globally\ndebugHttp();\n\nconsole.log('Making an HTTP GET request to google.com...');\nhttp.get('http://google.com', (res) => {\n  console.log(`HTTP GET to google.com status: ${res.statusCode}`);\n  res.resume(); // Consume response data to free up memory\n}).on('error', (e) => {\n  console.error(`HTTP GET error: ${e.message}`);\n});\n\nconsole.log('Making an HTTPS GET request to github.com...');\nhttps.get('https://github.com', (res) => {\n  console.log(`HTTPS GET to github.com status: ${res.statusCode}`);\n  res.resume(); // Consume response data\n}).on('error', (e) => {\n  console.error(`HTTPS GET error: ${e.message}`);\n});\n\n// Example with a custom handler function\n// debugHttp((type, data) => {\n//   console.log(`[${type.toUpperCase()}] Custom Handler:`, data.url || data.path);\n// });","lang":"javascript","description":"This example demonstrates how to enable global HTTP/HTTPS request debugging and then make a simple HTTP and HTTPS GET request, logging their status. It also shows a commented-out custom handler."},"warnings":[{"fix":"Thoroughly test your application when using global patching modules. Consider alternatives like `request-debug` for specific HTTP client libraries, or the `debug` package for application-level logging that doesn't modify core modules.","message":"This package globally patches Node.js's built-in `http` and `https` modules. This can lead to unexpected behavior or conflicts if other modules in your application also attempt to patch these core modules or rely on their unpatched behavior. Use with caution in larger applications.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Evaluate modern alternatives like `debug` for general-purpose debugging or specific debugging middleware/tools for your HTTP client (e.g., `axios-debug-log` for Axios). If using it, pin the exact version and consider forking if critical updates are needed.","message":"The `debug-http` package is unmaintained, with its last update over 10 years ago. It may not be compatible with newer Node.js versions, modern HTTP features, or security best practices, and will not receive updates for bugs or vulnerabilities.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your project is configured for CommonJS, or use dynamic `import()` for ESM projects: `const debugHttp = await import('debug-http'); debugHttp.default();` (though this package exports directly, so `debugHttp()` after dynamic import is likely correct).","message":"The package only supports CommonJS module loading (`require`). Attempting to `import debugHttp from 'debug-http'` in an ESM context will result in an error or undefined behavior due to the lack of an explicit ESM export.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Correct the CommonJS import to `const debugHttp = require('debug-http');` and then call `debugHttp();`.","cause":"This error often occurs when attempting to destructure the `require` result, or if using `require('debug-http').debugHttp` in CommonJS. The package directly exports the function, not an object with a named export.","error":"TypeError: debugHttp is not a function"},{"fix":"If your project is ESM, either switch back to CommonJS, configure Node.js to handle CJS in ESM (e.g., `\"type\": \"commonjs\"` in `package.json`), or use a dynamic import: `const debugHttpModule = await import('debug-http'); debugHttpModule.default();` (though for `debug-http`, it's `debugHttpModule()`).","cause":"This package is a CommonJS module and cannot be directly `require()`d from an ES Module context without specific Node.js configuration or dynamic imports.","error":"ERR_REQUIRE_ESM: require() of ES Module ... not supported"}],"ecosystem":"npm","meta_description":null}