Projects › Intermediate
Blog Platform with Authentication
A full MERN app where users sign up, write Markdown posts, comment and like — the project most MERN interviews ask about.
Level: Intermediate · Time: 2 weeks · Tech stack: MongoDB, Express, React, Node.js, JWT
Features to build
- Sign up / login with JWT and hashed passwords
- Create, edit, delete posts in Markdown with a cover image
- Comments, likes and tags
- Search and pagination
- Author profile pages
What you will learn
- JWT authentication
- Protected routes (frontend + backend)
- Relations with populate
- Image upload
- Pagination
Step-by-step guide
1. Backend structure
models/ (User, Post, Comment) · routes/ · middleware/auth.js · controllers/.
2. Auth
Hash passwords with bcrypt, return a JWT on login, and verify it in a middleware:
export function protect(req, res, next) {
const token = req.headers.authorization?.split(' ')[1];
try { req.user = jwt.verify(token, process.env.JWT_SECRET); next(); }
catch { res.status(401).json({ message: 'Please log in' }); }
}
3. Posts API with ownership checks
PATCH /api/posts/:id must check post.author.equals(req.user.id) — otherwise anyone can edit anyone's post (an IDOR bug).
4. Pagination and search
const q = search ? { $text: { $search: search } } : {};
const posts = await Post.find(q).sort({ createdAt: -1 }).skip((page - 1) * 10).limit(10).populate('author', 'name');
Add a text index on title and body.
5. Images
Upload with multer to Cloudinary (free tier) and store only the URL.
6. React frontend
React Router pages, an AuthContext holding the user, axios with an interceptor adding the token, and a Markdown editor (react-markdown for preview). Sanitize HTML.
7. Deploy
Backend on Render, frontend on Vercel, database on MongoDB Atlas. Set CORS to your frontend URL only.
Level it up
- Rich text editor and drafts
- Follow authors and a personalised feed
- SEO with Next.js server rendering
On your resume
- Developed a MERN blogging platform with JWT auth, role/ownership checks, Markdown posts, comments, likes, full-text search and pagination; deployed on Render, Vercel and Atlas.