แซแแ 17 แตแแ
แญแถแฝ แแ แ แแต แแแ! แแ Blog App แจแแฎ! ๐ฅ
All 17 lessons combined โ build a complete full-stack Blog App from scratch!
MERN = 4 technologies แ แแต แแญ โ แแ Web App แแแตแซแต แจแแซแตแแแ แแแ! Frontend + Backend + Database แแ JavaScript แฅแป!
MERN = Full stack with ONE language (JavaScript) โ same code structure frontend and backend!
๐๏ธ MERN Architecture โ แแ แแตแ:
Blog App โ Users register/login, posts แญแแฅแซแแฃ แซแแฃแแฃ แญแฐแญแแ! แแแ MERN technologies แ แแต แแญ!
A full blog platform โ users sign up, log in, create posts, read others' posts, and delete their own.
แแแ API Routes โ Backend แญแแธแแ:
| METHOD | PATH | DESCRIPTION | AUTH |
|---|---|---|---|
| POST | /api/auth/register | แ แฒแต user แแแแฃ / Register | Public |
| POST | /api/auth/login | Login โ JWT token | Public |
| GET | /api/posts | แแแ posts แซแแฃ / All posts | Public |
| GET | /api/posts/:id | แ แแต post / Single post | Public |
| POST | /api/posts | แ แฒแต post แแ แญ / Create post | ๐ Auth |
| PUT | /api/posts/:id | Post แแญแญ / Update post | ๐ Auth |
| DELETE | /api/posts/:id | Post แฐแญแ / Delete post | ๐ Auth |
| PUT | /api/posts/:id/like | Post แ แแฐแต / Like post | ๐ Auth |
const postSchema = new mongoose.Schema({ title: { type: String, required: true, trim: true }, content: { type: String, required: true }, author: { type: mongoose.Schema.Types.ObjectId, ref: 'User', // User model แแญ แซแซแญแแ required: true, }, tag: { type: String, enum: ['tech','life','edu'], default: 'tech' }, likes: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }], createdAt: { type: Date, default: Date.now }, }, { timestamps: true }); const Post = mongoose.model('Post', postSchema); module.exports = Post;
// GET แแแ posts โ populate author name router.get('/', async (req, res) => { const posts = await Post.find() .populate('author', 'name email') // author info แจแแญ .sort({ createdAt: -1 }); res.json({ success: true, data: posts }); }); // POST แ แฒแต post โ protect middleware router.post('/', protect, async (req, res) => { const post = await Post.create({ ...req.body, author: req.user.id, // JWT แแตแฅ แซแ user id }); res.status(201).json({ success: true, data: post }); }); // PUT like/unlike toggle router.put('/:id/like', protect, async (req, res) => { const post = await Post.findById(req.params.id); const liked = post.likes.includes(req.user.id); if (liked) { post.likes = post.likes.filter(id => id != req.user.id); // unlike } else { post.likes.push(req.user.id); // like } await post.save(); res.json({ success: true, likes: post.likes.length }); });
import { useState, useEffect } from 'react'; import { useAuth } from '../context/AuthContext'; function Home() { const [posts, setPosts] = useState([]); const [title, setTitle] = useState(''); const [content, setContent] = useState(''); const { user, token } = useAuth(); // Context แฐแ แ แ // Mount แฒแแ posts load แซแตแญแ useEffect(() => { fetchPosts(); }, []); async function fetchPosts() { const res = await fetch('/api/posts'); const data = await res.json(); setPosts(data.data); } async function createPost() { await fetch('/api/posts', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`, }, body: JSON.stringify({ title, content }), }); fetchPosts(); // Reload } return ( <div> {posts.map(p => ( <PostCard key={p._id} post={p} onLike={likePost} /> ))} </div> ); }
แแ MERN Blog App แแณแ! Posts แแ แญแฃ Like แ แตแญแแฃ แฐแญแ! Users แ แตแฐแณแตแญ! Stats แญแแแจแต! ๐ฅ
Everything working together โ posts, users, likes, delete, live stats and API log!
App แฐแญแถ แจแแ Internet แแญ แแแแ แแณแซ แแ! Backend + Frontend + Database แแ แแแฝ แฐแแฝ แแแแต แญแฝแแ!
After building, deploy so anyone can access your app from anywhere on the internet!
Components, Props, useState, useEffect, Context, Router โ แแแ แ แฅแฎ แฐแญแถ แแแ UI แญแฐแซแ!
Lessons 10-14: React is the face of the app โ what users see and interact with.
REST API routes, Middleware, Auth, JSON responses โ React แ แแ แญแฐแฃแ!
Lesson 15: Express handles all the business logic and serves data to React.
Documents, Schema, CRUD, Populate, Query โ แแแ แแแฅ แแ แแ แญแแแฃแ!
Lesson 16: MongoDB stores all data permanently โ users, posts, likes, everything.
Password hash, Token auth, Protected routes โ แแแ แฐแ
แแแฑ แ แฅแ แญแฐแซแ!
Lesson 17: Security layer โ bcrypt hashes passwords, JWT protects routes.
็ฅ่ดบ! Congratulations! 18 แตแแ แญแถแฝ แจแจแฐแ ! HTML โ CSS โ JS โ React โ Node โ MongoDB โ Auth โ Full Stack! ๐
แแฃแญ: TypeScript, Next.js, Docker, AWS... โจ
๐ ethiocodesoftselect.netlify.app
แปแแแ แญแแฑ โ Join ๐