I am developing apis with nodejs. I have seen there is a parameter passed in the function with req, res
like this:
bookRouter.use('/:bookId', function(req,res,next){
Book.findById(req.params.bookId, function(err,book){
if(err)
res.status(500).send(err);
else if(book)
{
req.book = book;
next();
}
else
{
res.status(404).send('no book found');
}
});
});
I never used this function in my development and I want to know if i really need to use this?