Closed krishnadev7 closed 1 year ago
// Get All Post
router.route('/').get(async (req, res) => {
try {
const posts = await post.find({});
console.log(posts);
res.json({ success: true, data: posts }); // changed to res.json instead of res.status
} catch (error) {
res.sendStatus(500).json({
success: false,
message: 'Fetching posts failed, please try again',
});
}
});
getting following error while fetching posts from the mongodb it is showing error when i do response data to json format
at this part
successfully fetching posts from the mongodb when i do
console.log(response)