A modern blog application built with Node.js, Express, MongoDB, and React. This project features a comprehensive backend API with user authentication, blog post management, social features, and advanced admin functionality.
- User Registration - Secure user registration with username/password
- User Login/Logout - JWT-based authentication with secure cookie handling
- Profile Management - Edit user profiles and manage personal information
- Account Deletion - Secure account deletion functionality
- Login History - Track user login activities
- Public Profiles - View other users' public profiles
- Upload Profile Image - Upload and update profile pictures using Cloudinary
- Delete Profile Image - Remove profile images with cloud storage cleanup
- Image Storage - Secure cloud-based image storage with public_id tracking
- Email Addition - Add email addresses to user accounts
- Email Verification - Secure email verification with OTP codes
- Email Change - Change email addresses with verification process
- Verification Cancellation - Cancel pending email verification processes
- Password Change - Secure password change for authenticated users
- Forgot Password - Password reset functionality with email verification
- Password Reset Verification - OTP-based password reset verification
- Reset Cancellation - Cancel pending password reset processes
- Create Posts - Create blog posts with text content and images
- Update Posts - Edit existing blog posts
- Delete Posts - Remove blog posts with proper cleanup
- View Posts - Get all posts or specific post by ID
- Image Upload - Upload images for blog posts using Cloudinary
- Like System - Like and unlike blog posts
- Comment System - Add, edit, and delete comments on posts
- Bookmark System - Save posts to personal bookmarks
- View Comments - Get all comments for a specific post
- Admin Dashboard - Overview of users, verified users, and posts
- User Management - View all users, verified users, and user details
- Post Management - View all posts and manage content
- User Deletion - Delete users by admin
- Post Deletion - Delete any post by admin
- Admin Authentication - Role-based access control for admin functions
- JWT Authentication - Secure token-based authentication
- Password Hashing - Bcrypt password encryption
- CORS Configuration - Cross-origin resource sharing setup
- Input Validation - Request validation and sanitization
- Rate Limiting - Protection against brute force attacks
- Role-based Access - Admin and user role management
- Node.js - JavaScript runtime environment
- Express.js - Web application framework
- MongoDB - NoSQL database
- Mongoose - MongoDB object modeling
- JWT - JSON Web Token authentication
- Bcrypt - Password hashing
- Multer - File upload handling
- Cloudinary - Cloud image storage
- Nodemailer - Email sending functionality
- CORS - Cross-origin resource sharing
- Cookie Parser - Cookie handling
- Nodemon - Development server with auto-restart
- Dotenv - Environment variable management
BlogApi/
βββ Backend/
β βββ app.js # Express app configuration
β βββ index.js # Server entry point
β βββ package.json # Backend dependencies
β βββ config/
β β βββ cloudinary.js # Cloudinary configuration
β βββ controllers/
β β βββ user.controller.js # User-related operations
β β βββ admin.controller.js # Admin operations
β β βββ post.controller.js # Blog post operations
β β βββ comment.controller.js # Comment operations
β β βββ like.controller.js # Like operations
β β βββ bookmark.controller.js # Bookmark operations
β βββ db/
β β βββ index.js # Database connection
β βββ middlewares/
β β βββ auth.js # JWT authentication middleware
β β βββ isAdmin.js # Admin role verification
β β βββ multer.js # File upload middleware
β β βββ setUploadTraget.js # Upload target configuration
β βββ models/
β β βββ user.model.js # User data model
β β βββ post.model.js # Post data model
β β βββ comment.model.js # Comment data model
β βββ routes/
β β βββ user.routes.js # User API endpoints
β β βββ admin.routes.js # Admin API endpoints
β β βββ post.routes.js # Post API endpoints
β β βββ comment.routes.js # Comment API endpoints
β β βββ like.routes.js # Like API endpoints
β β βββ bookmark.routes.js # Bookmark API endpoints
β βββ utils/
β βββ sendEmail.js # Email utility functions
βββ Frontend/ # React frontend (in development)
- Node.js (v14 or higher)
- MongoDB
- Cloudinary account
- Gmail account for email functionality
-
Clone the repository
git clone <repository-url> cd BlogApi
-
Install backend dependencies
cd Backend npm install -
Environment Setup Create a
.envfile in the Backend directory:PORT=9000 MONGODB_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name CLOUDINARY_API_KEY=your_cloudinary_api_key CLOUDINARY_API_SECRET=your_cloudinary_api_secret MAIL_USER=your_gmail_address MAIL_PASS=your_gmail_app_password
-
Start the development server
npm run dev
The server will start on http://localhost:9000
POST /register- Register a new userPOST /login- User loginPOST /logout- User logout
GET /profile- Get user profilePUT /edit-profile- Edit user profilePOST /upload-profile- Upload profile imagePUT /update-profile-image- Update profile imageDELETE /delete-profile- Delete profile imageDELETE /delete- Delete user accountGET /profile/:username- Get public profileGET /login-history- Get login history
POST /bio- Add user bioPUT /bio- Update user bio
POST /add-email- Add email to accountGET /verify-email- Verify email with OTPPOST /change-email- Change email addressGET /cancel-email- Cancel email verification
POST /change-password- Change passwordPOST /forget-password- Initiate password resetPOST /verify-forget-password- Verify password resetPOST /cancel-forget- Cancel password reset
GET /- Get all postsGET /:id- Get specific postPOST /create- Create new postPUT /update/:id- Update postDELETE /del/:id- Delete post
POST /:id- Create comment on postGET /:id- Get comments for postPUT /:id- Edit commentDELETE /:id- Delete comment
POST /:id- Toggle like on post
POST /:id- Toggle bookmark on postGET /- Get bookmarked posts
GET /dashboard- Admin dashboard statisticsGET /users- Get all usersGET /users/verified- Get verified usersGET /user/:id- Get user detailsDELETE /user/:id- Delete userGET /posts- Get all post titlesGET /posts/:id- Get post detailsDELETE /post/:id- Delete post
The API uses JWT (JSON Web Tokens) for authentication. Protected routes require a valid token in the request headers or cookies.
Authorization: Bearer <token>
The application includes comprehensive email functionality:
- Email verification with OTP codes
- Password reset emails
- Secure email change process
- Configurable email templates
Images are stored using Cloudinary:
- Automatic image optimization
- Secure cloud storage
- Public ID tracking for cleanup
- Support for multiple image formats
- Separate storage for profile and post images
- Password Hashing: All passwords are hashed using bcrypt
- JWT Tokens: Secure authentication tokens
- Input Validation: Request data validation
- CORS Protection: Configured cross-origin requests
- Rate Limiting: Protection against abuse
- Secure Cookies: HTTP-only cookies for token storage
- Role-based Access: Admin and user permissions
- Backend API (100% Complete)
- User authentication system
- Profile management with image upload
- Email verification system
- Password reset functionality
- Blog post CRUD operations
- Comment system
- Like system
- Bookmark system
- Admin dashboard and management
- Database models and schemas
- Complete API route structure
- Security implementations
- Frontend development
- UI/UX design
- Real-time features
- Real-time notifications
- User following system
- Advanced search functionality
- Mobile app development
- Analytics dashboard
- Content moderation tools
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License.
Sheraz Hussain
For support and questions, please contact the development team or create an issue in the repository.
Note: The backend API is now complete with all core features implemented. The frontend is currently under development.