how to get data from response object in different middleware using express
In the middleware function, neither res.end function is getting called, nor next function is getting called in your middleware. Do something like this:
app.use(bodyParser.json());app.use(bodyParser.urlencoded({ extended: true }));app.use('/', function(req, res, next){ console.log('entry point'); res.json({name:"somename",age: 29}); next()});var middleware = function (req, res, next) { console.log('LOGGED'); res.end = function (req, res , next) { var data = res.data; //do some validation logic here next() }; next();};app.use(middleware);app.use((req, res) => res.end()); // here your end function will be calledvar port = process.env.PORT || 10010;app.listen(port);