router.route('/:productId').get(async (req, res) => {
try {
const product = await Product.findById(id)
if (!product) {
return res
.status(400)
.json({ success: false, message: 'product not found' })
}
res.json({ product })
} catch {
res
.status(400)
.json({ success: false, message: 'could not retrieve product ' })
}
})
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter