Debug HTTP/HTTPS Requests

1.1.0 · abandoned · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

const debugHttp = require('debug-http');
const http = require('http');
const https = require('https');

// Enable HTTP/HTTPS request debugging globally
debugHttp();

console.log('Making an HTTP GET request to google.com...');
http.get('http://google.com', (res) => {
  console.log(`HTTP GET to google.com status: ${res.statusCode}`);
  res.resume(); // Consume response data to free up memory
}).on('error', (e) => {
  console.error(`HTTP GET error: ${e.message}`);
});

console.log('Making an HTTPS GET request to github.com...');
https.get('https://github.com', (res) => {
  console.log(`HTTPS GET to github.com status: ${res.statusCode}`);
  res.resume(); // Consume response data
}).on('error', (e) => {
  console.error(`HTTPS GET error: ${e.message}`);
});

// Example with a custom handler function
// debugHttp((type, data) => {
//   console.log(`[${type.toUpperCase()}] Custom Handler:`, data.url || data.path);
// });

view raw JSON →