body parser meddling with req.on('end') callback.
arihantdaga opened this issue · comments
arihant daga commented
A weird bug started coming up recently.
I have defined
req.on('end', ()=>{
console.log('Request Ended,. Reduced active request counter');
});
But surprisingly if i am including body-parser this callback is not being called.
P.S - This is how i am including body-parser. Is there anything wrong with it ?
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
Douglas Wilson commented
Hi @arihantdaga this is because body parser reads the request to completion before moving on to the next middleware. This is why the entire body is present in req.body
. In Node.js, once you have consumed the stream, you can not consume it a second time.