Log Outgoing Node Http Requests

May 7, 2021

This morning I had to debug a node proxy and needed to verify the external service request

function requestLogger(httpModule){
    var original = httpModule.request
    httpModule.request = function(options, callback){
      console.log(options.href||options.proto+"://"+options.host+options.path, options.method)
      return original(options, callback)
    }
}

requestLogger(require('http'))

source: stackoverflow


Do you want to know something?→Click!