A RESTful API built using Node.js, Express and MongoDB.
-
User Authentication
- Register & Login with hashed passwords and JWT token generation.
- Protected routes with middleware-based token validation.
-
Blog Management (CRUD)
- Create, read, update and delete blog posts.
- Each blog contains a title, description, optional tags and creation date.
-
Advanced Features
- Add comments to blogs.
- Tag-based filtering.
- Text-based search (title & description).
- Sorting blogs by creation date (asc/desc).
- Pagination with
?pageand?limitquery support.
-
Validation & Error Handling
- Input validation using simple schema checks.
- Centralized error handling using Express middleware.
-
Code Structure
- Organized into
controllers,routes,models,middlewaresandconfig.
- Organized into
- Node.js
- Express.js
- MongoDB & Mongoose
- bcryptJS
- dotenv
- express-validator
- jsonwebtoken (JWT)
- nodemon
git clone https://github.com/notnayan/blog-platform-api
cd blog-platform-apinpm installCreate a .env file in the root and add your environment variables. Use the provided .env.example as a reference:
PORT= your_port
MONGODB_CONNECTION_STRING= your_mongodb_connection_string
JWT_SECRET_KEY= your_secret_keynpm run devServer will start at http://localhost:PORT
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
New user registration |
| POST | /api/auth/login |
User logs in |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/blogs |
Create a blog |
| GET | /api/blogs |
Get all blogs |
| GET | /api/blogs/:id |
Get blog by ID |
| PUT | /api/blogs/:id |
Update a blog |
| DELETE | /api/blogs/:id |
Delete a blog |
| POST | /api/blogs/:id/comments |
Add a comment |
📌 Note:
TheGET /api/blogsendpoint supports the following optional query parameters:
search— Search by title or description (e.g.?search=javascript)tag— Filter blogs by a specific tag (e.g.?tag=nodejs)sort— Sort by creation date (ascordesc) (e.g.?sort=desc)page&limit— Pagination support (e.g.?page=2&limit=5)You can combine them as needed, like:
/api/blogs?search=node&tag=backend&sort=desc&page=1&limit=10