How to Intercept Request and Response object in Express js | Nodejs Tutorial

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) {;

let oldSend = res.send;

res.send = function (data) {;

oldSend.apply(res, arguments);




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


Leave a Reply

Your email address will not be published. Required fields are marked *