In this video you are going to learn how to intercept request and response object in express js using a single middleware function and log each request and response into a file
middleware code
---------------------------
app.use(function(req, res, next) {
logger.info(req.body);
let oldSend = res.send;
res.send = function (data) {
logger.info(JSON.parse(data));
oldSend.apply(res, arguments);
}
next();
})
apply the above middleware function before calling any route.
I use winston logger to log request and response object into a file
must watch my previous video on how to log using winston
Watch video How to Intercept Request and Response object in Express js | Nodejs Tutorial online without registration, duration 04 minute 40 second in high hd quality. This video was added by user Technical Babaji 10 December 2019, don't forget to share it with your friends and acquaintances, it has been viewed on our site 17 thousand once and liked it 201 people.