Full-featured blogging API with JWT authentication, role-based access control, and MongoDB database. Supports creating, editing, publishing blogs with search and filter capabilities. Altschool Africa Backend Engineering project.
# Blog API - Backend
A RESTful API for a blogging platform built with Node.js, Express, and MongoDB. Features user authentication, blog management, and advanced filtering capabilities.
Full-featured blogging API with JWT authentication, role-based access control, and MongoDB database. Supports creating, editing, publishing blogs with search and filter capabilities. Altschool Africa Backend Engineering project.
## Features
- **JWT Authentication** - Secure user registration and login
- **Blog CRUD Operations** - Create, read, update, and delete blogs
- **Draft & Publish System** - Save blogs as drafts before publishing
- **Advanced Filtering** - Search by title, author, tags
- **Automatic Calculations** - Reading time based on word count
- **View Tracking** - Track blog read counts
- **Owner Authorization** - Users can only edit/delete their own blogs
## Tech Stack
- **Node.js** - JavaScript runtime
- **Express.js** - Web framework
- **MongoDB** - NoSQL database
- **Mongoose** - ODM for MongoDB
- **JWT** - Authentication tokens
- **bcryptjs** - Password hashing
## API Endpoints
### Authentication
```
POST /api/auth/register Register a new user
POST /api/auth/login Login user and get token
```
### Blogs
```
POST /api/blogs Create a new blog (requires auth)
GET /api/blogs Get all published blogs
GET /api/blogs/:id Get a single blog by ID
GET /api/blogs/user/me Get logged-in user's blogs (requires auth)
PATCH /api/blogs/:id Update a blog (requires auth, owner only)
DELETE /api/blogs/:id Delete a blog (requires auth, owner only)
```
## Installation & Setup
### Prerequisites
- Node.js
- MongoDB
### Steps
1. **Clone the repository**
```bash
git clone
github.com
cd blog-api
```
1. **Install dependencies**
```bash
npm install
```
1. **Create `.env` file in root directory**
```
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_secret_key
PORT=500 …