Can anyone please explain why this:
// this works
router.route('/videos')
.get((req, res)=>{
Video.find()
.exec()
.then(console.log);
});
// this also works
router.route('/videos')
.get((req, res)=>{
Video.find()
.exec()
.then(videos=>{
res.json(videos)
});
});
works, and this:
router.route('/videos')
.get((req, res)=>{
Video.find()
.exec()
.then(res.json);
});
doesn't?
The res
object represents the HTTP response that an Express.js app sends when it gets an HTTP request. The console.log
method outputs the videos data while res.json
does not seem to be called.