I'm having an issue with a node app I've written using express. In order to help debug the issue, I want to print out every HTTP message that the app sends or receives to the console. I've tried this:
app.use('/', (req, res, next) => { console.log(req) console.log(res) next() }) But the issue is the objects res and req that get printed here don't include the info I need. They are an HTTP.ServerResponse and HTTP.IncomingMessage object, respectively. There is no body element in res (i.e. the response my app is sending), and I can't figure out how to get it. I've tried this as well:
app.use('/', (req, res, next) => { var data = '' res.on('data', chunk => { data+=chunk }) res.on('end', () => { console.log(data) next() }) }) But that causes the server to hang. next() never gets called.
How can I do what I want?