This Blogging API is a fully-featured RESTful backend application designed to demonstrate mastery of core backend engineering concepts using Node.js and Express.
The system allows users to register, authenticate securely using JWT, and manage blog posts with proper access control. Public users can access only published blogs, while authenticated users can create, edit, publish, or delete their own blog posts.
This project demonstrates:
- REST API architecture
- Secure authentication and authorization
- Proper database modeling using Mongoose
- Pagination, filtering, and sorting implementation
- Clean MVC architecture separation
- Middleware usage
- Environment-based configuration
- Deployment readiness
Special attention was given to writing clean, modular, and scalable code structure to reflect real-world backend engineering practices.
Base URL: https://altschool-blogging-api-1c6f.onrender.com (Update with your actual deployed link)
- Node.js
- Express.js
- MongoDB Atlas
- Mongoose ODM
- JSON Web Token (JWT)
- bcryptjs
- Render (Deployment)
├── config/
│ └── db.js
├── controllers/
│ ├── authController.js
│ └── blogController.js
├── middleware/
│ └── auth.js
├── models/
│ ├── User.js
│ └── Blog.js
├── routes/
│ ├── authRoutes.js
│ └── blogRoutes.js
├── tests/
├── .env.example
├── app.js
├── server.js
├── package.json
└── README.md
The project follows the MVC pattern to ensure maintainability and separation of concerns.
- JWT Token expires after 1 hour
- Passwords hashed using bcrypt
- Protected routes secured with middleware
- Owner-only blog modification enforced at controller level
Authorization Header Format:
Authorization: Bearer <token>{=html}
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/signup | Register a new user |
| POST | /api/auth/signin | Login user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/blogs | Get all published blogs |
| GET | /api/blogs/:id | Get single published blog |
Features Implemented:
- Pagination (default 20 per page)
- Search by title, author, tags
- Sorting by read_count, reading_time, createdAt
- Order control (asc/desc)
- Read count increment on single blog fetch
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/blogs | Create blog (default: draft) |
| GET | /api/blogs/user/me | Get current user's blogs |
| PUT | /api/blogs/:id | Update blog (owner only) |
| DELETE | /api/blogs/:id | Delete blog (owner only) |
Reading time is calculated using an average reading speed of 200 words per minute.
const wordCount = body.split(/`\s`{=tex}+/).length;
const wordsPerMinute = 200;
reading_time = Math.ceil(wordCount / wordsPerMinute);A complete Postman collection is provided for easy testing of all endpoints.
Postman Collection Link: (Add your exported Postman collection link here)
Testing Flow:
- Signup
- Signin
- Copy JWT token
- Create blog (draft)
- Publish blog
- Test public endpoints
- Test pagination, search, sorting
✔ User model with required fields
✔ Signup endpoint
✔ Signin endpoint
✔ JWT authentication (1-hour expiry)
✔ Draft and Published states
✔ Public access to published blogs
✔ Owner-only update and delete
✔ Pagination implemented (default 20)
✔ Search by title, author, tags
✔ Sorting by read_count, reading_time, createdAt
✔ Reading time calculation
✔ Read count increment on single blog fetch
✔ Postman collection for testing
| Variable | Required | Description |
|---|---|---|
| MONGODB_URI | Yes | MongoDB connection string |
| JWT_SECRET | Yes | Secret for JWT signing |
| PORT | No | Server port |
| NODE_ENV | No | Environment type |
This project was created strictly for educational purposes as part of the AltSchool Africa Backend NodeJS Second Semester Examination.
George Owoicho
AltSchool Africa Backend Student
GitHub: https://github.com/devGeorgeOwi/altschool-blogging-api