log-that-http

raw JSON →
1.0.1 verified Sat Apr 25 auth: no javascript maintenance

Monkey-patches Node.js built-in http/https modules to log outgoing requests and responses to console. v1.0.1 is the current stable release; last updated in 2019. No dependencies, supports Node >=8. Works transparently with axios, got, node-fetch, request, superagent, and native http/https. Controlled via environment variables (LOG_THAT_HTTP_HEADERS, LOG_THAT_HTTP_BODY). Not actively maintained, but functional for debugging. Contrasts with request-intercepting libraries like nock or mockttp by focusing on logging without mocking.

error Cannot find module 'log-that-http'
cause Package not installed or wrong import style.
fix
Run 'npm install log-that-http' and use require('log-that-http').
error LOG_THAT_HTTP_HEADERS is not defined
cause Trying to access environment variable as a module export.
fix
Use process.env.LOG_THAT_HTTP_HEADERS = 'true' before require.
error TypeError: http.get is not a function
cause Package may be monkey-patching http module incorrectly on newer Node versions.
fix
Upgrade to a maintained logger or restrict Node version to <14.
breaking Known incompatibility with Node.js >=14 due to internal http module changes.
fix Use only on Node.js 8–13 or test with your specific library.
deprecated Package last updated in 2019; no longer maintained.
fix Consider alternatives like 'pino-http' or 'morgan' for active logging solutions.
gotcha Monkey-patches http/https globally; may interfere with other packages that also patch these modules.
fix Load log-that-http first, before other http-modifying libraries.
gotcha Environment variables must be set before the module is required; changing them later has no effect.
fix Set LOG_THAT_HTTP_HEADERS and LOG_THAT_HTTP_BODY before require('log-that-http').
npm install log-that-http
yarn add log-that-http
pnpm add log-that-http

Shows activating log-that-http with env vars and making a simple HTTP GET request. Logs request/response headers and body automatically.

// Enable via environment variables before requiring the package
process.env.LOG_THAT_HTTP_HEADERS = 'true';
process.env.LOG_THAT_HTTP_BODY = 'true';

require('log-that-http');

const http = require('http');
http.get('http://example.com', (res) => {
  let data = '';
  res.on('data', chunk => data += chunk);
  res.on('end', () => console.log('Done'));
}).on('error', console.error);