Skip to content

Latest commit

 

History

History
220 lines (151 loc) · 2.32 KB

File metadata and controls

220 lines (151 loc) · 2.32 KB

Blog Backend API (MERN Stack)

A RESTful Blog Backend API built using Node.js, Express, and MongoDB. This project demonstrates CRUD operations, pagination, likes, and comments functionality for blog posts.


🚀 Features

  • Create Blog Post
  • Update Blog Post
  • Delete Blog Post
  • Like a Post
  • Comment on a Post
  • Pagination for Posts
  • Clean MVC-style backend structure

🛠 Tech Stack

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose
  • Nodemon
  • Dotenv

📁 Project Structure

blog-backend-api
│
├── config
│   └── db.js
│
├── controllers
│   └── postController.js
│
├── models
│   └── Post.js
│
├── routes
│   └── postRoutes.js
│
├── .env
├── server.js
└── package.json

⚙️ Installation

Clone the repository

git clone https://github.com/yourusername/blog-backend-api.git

Move into the project

cd blog-backend-api

Install dependencies

npm install

🔐 Environment Variables

Create a .env file in the root directory.

Example:

PORT=5000
MONGO_URI=mongodb://127.0.0.1:27017/blogDB

▶️ Run the Server

Start development server

npm run dev

Server will run on

http://localhost:5000

📌 API Endpoints

Create Post

POST /api/posts

Body

{
 "title": "My First Blog",
 "content": "This is my first blog post"
}

Get Posts (Pagination)

GET /api/posts?page=1&limit=5

Update Post

PUT /api/posts/:id

Body

{
 "title": "Updated Blog Title"
}

Delete Post

DELETE /api/posts/:id

Like Post

POST /api/posts/:id/like

Add Comment

POST /api/posts/:id/comment

Body

{
 "text": "Great blog!"
}

🧪 API Testing

You can test APIs using:

  • Thunder Client (VS Code)
  • Postman

📦 Example Response

{
 "title": "First Blog",
 "content": "Testing local MongoDB",
 "likes": 1,
 "comments": [],
 "createdAt": "2026-03-09T10:22:35.639Z"
}

🎯 Learning Outcomes

This project helped practice:

  • REST API development
  • MongoDB schema design
  • Pagination
  • Express routing
  • MVC backend structure

👨‍💻 Author

Mitesh Nadiyapara

MERN Stack Developer