From dbbee518ccbbcef5f72905626d4f9b64c2391a35 Mon Sep 17 00:00:00 2001 From: JaberHPranto Date: Wed, 15 Sep 2021 23:50:26 +0600 Subject: [PATCH] getting all posts --- server/controller/blogController.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/controller/blogController.js b/server/controller/blogController.js index 8a569f5..6ab02fc 100644 --- a/server/controller/blogController.js +++ b/server/controller/blogController.js @@ -1,7 +1,14 @@ import BlogPost from '../models/blogModel.js'; // Get all blog posts -export const getBlogs = (req, res) => { - res.send("Everything works !!!") +export const getBlogs = async (req, res) => { + try { + const blogs = await BlogPost.find() + res.status(200).json(blogs) + } catch (err) { + res.status(401).json({ + error: err.message + }) + } } // Create a blog