LEARN EXPRESS MIDDLEWARE req.on and related middleware

what is req.on? i cant comprehend it?

my interpretation of this code is:
app.use is applying “middleware” to these specific routes. this is doing something with the request object, i guess its adding all the data of the request object to a variable named bodyData

i dont know what req.on is, i dont know what the string ‘data’ or the string ‘end’ represents… theyre not routes from my understanidng i dont know what they are.

req.on

app.use([’/beans/’, ‘/beans/:beanName’], (req, res, next) => {

let bodyData = ‘’;

req.on(‘data’, (data) => {

bodyData += data;

});

req.on(‘end’, ()=>{

if (bodyData) {

req.body = JSON.parse(bodyData);

}

next()

})

})

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.