A full-stack blog application built with MongoDB, Express.js, React, and Node.js. This platform allows users to create, read, update, and delete blog posts with user authentication and social features.
- User Registration & Login - Secure authentication with JWT tokens
- Password Reset - Email-based password recovery system
- User Profiles - Personal profile pages for each user
- Account Management - Update user information and delete accounts
- Create Posts - Write and publish blog posts with titles, descriptions, and images
- Edit Posts - Modify your existing posts
- Delete Posts - Remove posts you've created
- View Posts - Browse all posts with detailed view pages
- My Blogs - View all posts created by a specific user
- Search & Sort - Search posts by title and sort by newest, oldest, or alphabetically
- Image Upload - Add images to your blog posts
- Categories - Organize posts with categories
- Likes & Dislikes - React to posts with likes or dislikes
- Ratings - Rate posts on a 5-star scale
- Comments - Add, edit, and delete comments on posts
- View Counter - Track post views automatically
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM for MongoDB
- JWT - Authentication tokens
- bcrypt - Password hashing
- Multer - File upload handling
- Nodemailer - Email service for password reset
- cookie-parser - Parse cookies
- cors - Cross-origin resource sharing
- dotenv - Environment variables
- React - UI library
- React Router DOM - Client-side routing
- Tailwind CSS - Styling framework
- Vite - Build tool
- Node.js (v14 or higher)
- MongoDB (local or Atlas)
- npm or yarn
- Clone the repository
git clone <repository-url>
cd blog-website- Install backend dependencies
cd backend
npm install- Create a
.envfile in the backend directory
MONGO_URL=your_mongodb_connection_string
PORT=5000
SECRET=your_jwt_secret_key
EMAIL=your_gmail_address
PASS=your_gmail_app_password- Start the backend server
npm startThe backend will run on http://localhost:5000
- Install frontend dependencies
cd frontend
npm install- Start the development server
npm run devThe frontend will run on http://localhost:5173
POST /api/auth/register- Register a new userPOST /api/auth/login- Login userGET /api/auth/logout- Logout userGET /api/auth/refetch- Refetch user data
GET /api/users/:id- Get user by IDPUT /api/users/:id- Update userDELETE /api/users/:id- Delete userPOST /api/users/forgotPassword- Send password reset emailPOST /api/users/resetPassword/:id/:token- Reset password
GET /api/posts- Get all posts (with search and sort)GET /api/posts/:id- Get post by ID (increments views)GET /api/posts/user/:userId- Get posts by userPOST /api/posts/create- Create new postPUT /api/posts/:id- Update postDELETE /api/posts/:id- Delete postPUT /api/posts/:id/like- Like a postPUT /api/posts/:id/dislike- Dislike a postPOST /api/posts/:id/rate- Rate a post
GET /api/comments/post/:postId- Get comments for a postPOST /api/comments/create- Create commentPUT /api/comments/:id- Update commentDELETE /api/comments/:id- Delete comment
POST /api/upload- Upload image
- username (String, required, unique)
- email (String, required, unique)
- password (String, required, hashed)
- timestamps
- title (String, required, unique)
- desc (String, required, unique)
- photo (String, optional)
- username (String, required)
- userId (String, required)
- categories (Array)
- likes (Number, default: 0)
- dislikes (Number, default: 0)
- likedBy (Array of User IDs)
- dislikedBy (Array of User IDs)
- views (Number, default: 0)
- ratings (Array of objects with userId and rating)
- averageRating (Number, default: 0)
- timestamps
- comment (String, required)
- author (String, required)
- postId (String, required)
- userId (String, required)
- timestamps
The application uses JWT (JSON Web Tokens) for authentication:
- Tokens are stored in HTTP-only cookies
- Token expiration: 3 days
- Protected routes require valid token via
verifyTokenmiddleware
- User requests password reset via email
- System generates JWT token valid for 1 day
- Email sent with reset link
- User clicks link and enters new password
- Password is hashed and updated in database
- Users can like or dislike posts
- Liking removes dislike if present (and vice versa)
- Tracks which users liked/disliked each post
- Prevents duplicate likes/dislikes
- Users can rate posts 1-5 stars
- Each user can rate a post only once
- System calculates and stores average rating
- Average updates automatically when new ratings added