Skip to content

Instantly share code, notes, and snippets.

@paulobunga
Created December 18, 2019 00:19
Show Gist options
  • Save paulobunga/b4ec0bc02989e2789a2fb318c1d5af56 to your computer and use it in GitHub Desktop.
Save paulobunga/b4ec0bc02989e2789a2fb318c1d5af56 to your computer and use it in GitHub Desktop.
Code to return single product details based on the ID
Product.findOne({ _id: req.params.productId }).exec((error, result) => {
if (error) {
res.json({ status: 'ERROR', message: 'Error getting product' });
}
if (result) {
res.json({
status: 'SUCCESS',
message: 'Product found',
product: result,
});
} else {
res.json({ status: 'NO_PRODUCT', message: 'No product with specified product ID found' });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment