Skip to content

πŸ“ A basic blogging platform backend built with the MERN stack. Supports user authentication, post creation, and MongoDB data handling.

Notifications You must be signed in to change notification settings

buildwithmehul/mern-blog-backend-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Simple Blog Backend (v2)

A powerful backend API for a complete blogging platform where users can:

  • πŸ“ Create, read, update, delete blog posts
  • πŸ” Authenticate & secure their actions via JWT
  • ❀️ Like, πŸ“Œ bookmark, 🏷️ tag posts
  • πŸ’¬ Comment with threading
  • πŸ“Š View real-time platform analytics
  • 🧠 Manage content via full admin control

Built using Node.js, Express, MongoDB, and tested thoroughly with Postman.


πŸ› οΈ Tech Stack

  • Node.js
  • Express.js
  • MongoDB (Mongoose ODM)
  • JWT for authentication
  • Postman (API testing)

✨ Core Features

  • πŸ” User Authentication (JWT)
    Register, Login, Auth middleware

  • πŸ“ Blog CRUD
    Create, Read, Update, Delete blog posts
    Protected routes – only post owners can edit/delete

  • πŸ§‘ Post Ownership & Auth Checks
    Users can only modify their own posts

  • πŸ’¬ Comments System
    Add/view/delete comments per post
    Post authors can also delete comments

  • ❀️ Like System
    Toggle likes on posts; count likes dynamically

  • πŸ“Œ Bookmark System
    Bookmark/unbookmark posts; view in profile

  • 🏷️ Tag-based Filtering + Search
    Filter posts by tag or keyword

  • πŸ“¦ Pagination Support
    Paginated GET /posts?page=n for large datasets

  • πŸ“Š Analytics Dashboard
    Platform-wide stats on users, posts, likes, bookmarks
    Top liked/bookmarked posts, most active users

  • 🧠 Admin Panel
    Admin can:

    • View all users
    • Delete any post/comment
    • Freeze/unfreeze users (prevent posting)
    • Promote users to admin
    • View full admin summary dashboard

πŸ“ Folder Structure

simple-blog-backend/
β”œβ”€β”€ index.js
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ auth.js
β”‚   β”œβ”€β”€ posts.js
β”‚   β”œβ”€β”€ comments.js
β”‚   β”œβ”€β”€ users.js
β”‚   β”œβ”€β”€ analytics.js
β”‚   └── admin.js
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ User.js
β”‚   β”œβ”€β”€ Post.js
β”‚   └── Comment.js
β”œβ”€β”€ middleware/
β”‚   β”œβ”€β”€ authMiddleware.js
β”‚   └── adminMiddleware.js
β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ authController.js
β”‚   └── commentController.js
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ generateToken.js
β”œβ”€β”€ package.json
β”œβ”€β”€ .env
β”œβ”€β”€ node_modules/
β”œβ”€β”€ screenshots/ # Postman test screenshots

πŸš€ Getting Started

Prerequisites


πŸ”§ Installation & Run

git clone https://github.com/KhannaSahab16/Simple-Blog-Backend.git
cd Simple-Blog-Backend
npm install
node index.js

Server will run on: http://localhost:3000 (default)


πŸ§ͺ API Testing via Postman

All endpoints can be tested via Postman (screenshots inside screenshots/ folder).

πŸ“ Public Routes

Method Endpoint Description
POST /api/auth/register Register new user
POST /api/auth/login Login and get token

πŸ” Protected Blog Routes

Method Endpoint Description
POST /api/posts Create a new post
GET /api/posts Get paginated posts
GET /api/posts/:id Get single post + comments
PUT /api/posts/:id Update your post
DELETE /api/posts/:id Delete your post

πŸ’¬ Comments Routes

Method Endpoint Description
POST /api/comments/:postId Add comment to post
DELETE /api/comments/:id Delete comment (self/post author)

❀️ Likes & πŸ“Œ Bookmarks

Method Endpoint Description
PUT /api/posts/like/:id Like/unlike a post
PUT /api/users/bookmark/:postId Bookmark/unbookmark
GET /api/users/profile View user bookmarks, likes, stats

πŸ“Š Analytics Routes

Method Endpoint Description
GET /api/analytics/dashboard Platform-wide metrics

🧠 Admin Routes

Method Endpoint Description
GET /api/admin/users View all users
DELETE /api/admin/posts/:id Delete any post
DELETE /api/admin/comments/:id Delete any comment
PUT /api/admin/promote/:id Promote user to admin
PUT /api/admin/freeze/:id Freeze/unfreeze user
GET /api/admin/summary View user/post analytics

🧠 Author

Mehul Khanna

🧠 Backend Dev Intern · Clean Architecture Fan · Builder of Bold Ideas

About

πŸ“ A basic blogging platform backend built with the MERN stack. Supports user authentication, post creation, and MongoDB data handling.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published