I followed your tutorial on youtube (thanks again for the great tutorial ), and I had to adapt the blog_details controller at two points for not running into errors (see (1) and (2) in the code snippet below):
const blog_details = (req, res) => {
//(1) id contains a space as first character, I don't know why, I have to remove it
const id = req.params.id.slice(1)
Blog.findById(id).then(result => {
//(2) if blog is not found result = null, I have to check for that for preventing error at this point,
// otherwise the webpage hangs
// you can trigger this behaviour by using a valid blog id and then change e.g. the last digit
if(result != null)
res.render('./blogs/details', { blog: result, title: 'Blog Details' })
else
res.status(404).render('404', {title: 'Blog not found' })
}).catch( err => {
console.log(err)
// you can trigger this behavior e.g. with /blogs/isajfjklsfnhhsafkhnbsdf
res.status(404).render('404', {title: 'Site not found' })
})
}