Skip to content

Instantly share code, notes, and snippets.

@selbyk
Created January 18, 2017 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save selbyk/9fec0e69e50f38e02ebd40792fb87cb6 to your computer and use it in GitHub Desktop.
Save selbyk/9fec0e69e50f38e02ebd40792fb87cb6 to your computer and use it in GitHub Desktop.
log all node.js http/https requests
let reqCount = 0;
function requestLogger(httpModule) {
var original = httpModule.request;
httpModule.request = function(options, callback) {
console.log(reqCount++, options.method, options.href || options.proto + "://" + options.host + options.path);
console.log(options.uri);
console.log(options.headers);
return original(options, callback);
}
}
requestLogger(require('http'));
requestLogger(require('https'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment