A robust backend API for a personal blogging platform built with Node.js, Express, and MongoDB.
- 🔐 User Authentication (Register, Login, Logout)
- 📝 Blog Post Management (Create, Read, Update, Delete)
- 💬 Comment System
- 🖼️ Image Upload with Cloudinary
- 🔄 Token-based Authentication
- ⚡ Rate Limiting
- 🛡️ Error Handling
- 📦 TypeScript Support
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB
- Language: TypeScript
- Authentication: JWT
- File Storage: Cloudinary
- Validation: Express Validator
- Security: bcrypt, helmet
- Rate Limiting: express-rate-limit
- Node.js (v14 or higher)
- MongoDB
- Cloudinary Account (for image uploads)
- Git
Create a .env file in the root directory with the following variables:
PORT=8800
MONGODB_URI=your_mongodb_uri
ACCESS_TOKEN_SECRET=your_access_token_secret
REFRESH_TOKEN_SECRET=your_refresh_token_secret
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_EXPIRY=7d
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret- Clone the repository:
git clone https://github.com/yourusername/personalBlogBackend.git
cd personalBlogBackend- Install dependencies:
npm install- Start the development server:
npm run devPOST /api/v1/auth/register- Register a new userPOST /api/v1/auth/login- Login userPOST /api/v1/auth/logout- Logout user
GET /api/v1/posts- Get all postsGET /api/v1/posts/:id- Get a single postPOST /api/v1/posts- Create a new postPUT /api/v1/posts/:id- Update a postDELETE /api/v1/posts/:id- Delete a post
GET /api/v1/comments/:postId- Get comments for a postPOST /api/v1/comments- Add a commentPUT /api/v1/comments/:id- Update a commentDELETE /api/v1/comments/:id- Delete a comment
- app.ts: Main application file that sets up Express, middleware, and routes
- controllers/: Handle business logic and request processing
- models/: Define database schemas and methods
- routes/: Define API endpoints and route handlers
- types/: TypeScript interfaces for type safety
- utils/: Reusable utility functions and configurations
- .env: Environment variables for configuration
- tsconfig.json: TypeScript compiler options
- package.json: Project metadata and dependencies