Blog platform with login (MERN)
Users sign up, write posts with images, comment and like; a complete MERN app with authentication.
What you'll learn
- âREST API design with Express
- âMongoDB models with Mongoose
- âAuth with hashed passwords and httpOnly cookies
What you'll build
- âSign up / log in / log out
- âCreate, edit, delete your posts
- âComments and likes
- âSearch and pagination
Step-by-step guide
- 1
Backend setup
npm init; npm i express mongoose bcrypt jsonwebtoken cookie-parser cors dotenv; connect with mongoose.connect(process.env.MONGO_URL).
- 2
Models
User {name, email unique, passwordHash}, Post {title, body, author ref, likes [ref], createdAt}, Comment {post, author, text}.
- 3
Auth
Hash with bcrypt; on login sign a JWT and send it in an httpOnly, secure, sameSite cookie; middleware verifies it and sets req.user.
- 4
Post routes
GET /api/posts?page=&q=, POST /api/posts (auth), PUT/DELETE /api/posts/:id (author only).
- 5
Front end
React with React Router: Home, Post, Editor, Login, Register; fetch with credentials: "include".
- 6
Validation and errors
Validate bodies (for example with zod), return 400/401/403/404 consistently and show them in the UI.
- 7
Deploy
MongoDB Atlas free tier for the database, the API and front end on a free hosting plan; keep secrets in environment variables.
đ Make it stand out
- +Image upload to cloud storage
- +Rich text editor
- +Email verification