📝 MyBlog
MyBlog is a full-stack blogging platform built using Node.js, Express, MongoDB, and EJS.
The application focuses on secure authentication, user-owned content, and clean backend architecture.
- The application is deployed
- ClickMe to view the live demo
- 👤 Allows users to create an account and authenticate securely
- 🔒 Ensures only signed-in users can create blogs
- 🧾 Restricts delete actions to content owners and admins
- 🗄️ Stores all data using structured MongoDB schemas
- Password hashing with salt
- JWT-based authentication
- Login and logout functionality
- Middleware-protected routes
- Unauthorized users cannot create blogs or comments
- Create blog posts with title and content and cover image
- Delete blogs only if you are the creator or the admin
- Ownership checks enforced on the server
- Add comments on blog posts
- Comments are linked to authenticated users
- Anonymous commenting is restricted
- Users can delete their own account
- Sessions are invalidated on logout
- Backend: Node.js, Express.js
- Database: MongoDB (Mongoose)
- Authentication: JWT
- Templating: EJS
controllers/
middlewares/
models/
routes/
services/
views/
public/
app.js
package.json
package-lock.json
.env
.gitignore
git clone <repository-url>
cd BLOGCopy code
npm installCreate a .env file in the root directory:
PORT=your_port
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secretnpm start
Open in browser:
http://localhost:PORT- Authentication is handled using JWT stored in cookies, with middleware-based user resolution.
POST /user/signupRegister a new user
POST /user/signinAuthenticate user and create session
GET /user/logoutLogout the current user
GET /Fetch and display all blogs (homepage)
GET /blog/add-newRender add blog form (authenticated users only)
GET /blog/:idFetch a specific blog along with its comments
POST /blogCreate a new blog with optional cover image upload
DELETE /blog/:idDelete a blog (author or admin only)
POST /blog/comment/:idAdd a comment to a specific blog
DELETE /blog/comment/:commentIdDelete a comment (comment author, blog owner, or admin only)
- 🚫 Blogs cannot be created without authentication
- 🛑 Users cannot delete blogs they do not own
- 🧠 Middleware validates JWT on protected routes
- 🔐 Passwords are never stored in plain text
- Edit blog functionality
- Upvote and Downvote
- View Blogs By Various Filters
- User Profiles
- Search optimization
- Admin moderation tools
Made with ❤️ by Anjali Mittal