I'm curious as to why the following code snippets behave differently:
// 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)
});
});
and why this doesn't work:
router.route('/videos')
.get((req, res)=>{
Video.find()
.exec()
.then(res.json);
});
I am trying to understand why one piece of code outputs data using console.log
, while another piece does not seem to call res.json
.