For registration / debugging, I would like to output the first hundreds of characters or so of the answer right before sending it to the browser. Is there something simple I can do with middleware and an answer object for this?
Ideally, this is something like:
app.use(function(req, res, next) { console.log('Response snippet: '+((res.body || '').substr(0,100))); next(); });
Except that the answer has no body, and I cannot figure out where the current body is being sent, which will be sent back.
UPDATE:
Peter's answer worked, I suppose I would put my middleware code in order to save future viewers with a click:
App.use(function(req, res, next) { var end = res.end; res.end = function(chunk, encoding){ res.end = end; if (chunk) { console.log(chunk); } res.end(chunk, encoding); }; next(); });
source share