I'd like to create some middleware that would log the request body and response body of all routes. Logging the request is straight forward, however, I can't seem to get the response. res.on('end')
doesn't emit any data and I'm not seeing anything specifically tied into express that would emit or apply this. Would anyone have any suggestions how to achieve this?
EDIT: Based on the links in kook's answer, I've come up with this, which seems to work well.
app.use(function(req, res, next) {
var send = res.send;
res.send = function(body){
console.log(body);
res.send = send;
res.send(body);
};
next();
});