app.get('/products', async (req, res) => {
try {
const products = await Product.find({})
res.json({ success: true, products })
} catch (err) {
res.status(500).json({
success: false,
message: 'unable to get products',
errorMessage: err.message,
})
}
})
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