A full-stack real-time chat application built with React, Node.js, Socket.io, and MongoDB.
- 🔐 User authentication (signup/login)
- 💬 Real-time messaging with Socket.io
- 👤 User profiles with image upload
- 🎨 Theme customization (light/dark mode)
- 📱 Responsive design with Tailwind CSS and DaisyUI
- 🔒 JWT-based authentication
- 🖼️ Image upload with Cloudinary
- React 18
- Vite
- Tailwind CSS + DaisyUI
- Zustand (state management)
- Socket.io-client
- React Router v7
- Axios
- Node.js + Express
- MongoDB with Mongoose
- Socket.io
- JWT authentication
- Cloudinary (image storage)
- bcrypt (password hashing)
Before running this application, make sure you have:
- Node.js (v14 or higher) - Download
- MongoDB - Either:
- Cloudinary Account (free tier available) - Sign up
git clone <repository-url>
cd Chat-appYou have two options:
npm run build# Install backend dependencies
cd backend
npm install
# Install frontend dependencies
cd ../frontend
npm install- Navigate to the backend directory:
cd backend- Create a
.envfile by copying the example:
# On Windows (PowerShell)
copy .env.example .env
# On Mac/Linux
cp .env.example .env- Edit the
.envfile with your configuration:
# MongoDB Configuration
MONGO_URI=mongodb://localhost:27017/chatapp
# For MongoDB Atlas, use:
# MONGO_URI=mongodb+srv://username:[email protected]/chatapp?retryWrites=true&w=majority
# JWT Secret (use a strong random string)
JWT_SECRET=your_super_secret_jwt_key_here_change_this
# Server Port
PORT=5001
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
# Environment
NODE_ENV=development- Start MongoDB service:
# Windows
net start MongoDB
# Mac (with Homebrew)
brew services start mongodb-community
# Linux
sudo systemctl start mongod- Create a free cluster at MongoDB Atlas
- Get your connection string
- Replace the
MONGO_URIin.envwith your connection string
- Create a free account at Cloudinary
- Go to your Dashboard
- Copy your Cloud Name, API Key, and API Secret
- Add them to your
.envfile
Terminal 1 - Backend:
cd backend
npm run devThe backend will start on http://localhost:5001
Terminal 2 - Frontend:
cd frontend
npm run devThe frontend will start on http://localhost:5173
First, build the frontend:
npm run buildThen start the application:
npm start- Build the application:
npm run build- Set NODE_ENV to production in backend/.env:
NODE_ENV=production- Start the server:
npm startThe application will be available at http://localhost:5001
Chat-app/
├── backend/
│ ├── src/
│ │ ├── controllers/ # Route controllers
│ │ ├── lib/ # Database, socket, utilities
│ │ ├── middleware/ # Auth middleware
│ │ ├── models/ # MongoDB models
│ │ ├── routes/ # API routes
│ │ └── index.js # Server entry point
│ └── package.json
├── frontend/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Page components
│ │ ├── store/ # Zustand stores
│ │ ├── lib/ # Utilities and axios config
│ │ └── App.jsx # Main app component
│ └── package.json
└── package.json # Root package.json
POST /api/auth/signup- User registrationPOST /api/auth/login- User loginPOST /api/auth/logout- User logoutPUT /api/auth/update-profile- Update user profileGET /api/auth/check- Check authentication status
GET /api/messages/users- Get all users for chatGET /api/messages/:userId- Get messages with specific userPOST /api/messages/send/:userId- Send message to user
-
MongoDB Connection Error
- Ensure MongoDB is running
- Check MONGO_URI in .env file
- For Atlas, whitelist your IP address
-
Port Already in Use
- Change PORT in backend/.env
- Kill the process using the port:
# Windows netstat -ano | findstr :5001 taskkill /PID <PID> /F # Mac/Linux lsof -i :5001 kill -9 <PID>
-
Cloudinary Upload Issues
- Verify your Cloudinary credentials
- Check if you've exceeded free tier limits
-
CORS Errors
- Ensure backend is running on port 5001
- Check cors configuration in backend/src/index.js
- Authentication: Secure JWT-based authentication with httpOnly cookies
- Real-time Messaging: Instant message delivery using Socket.io
- Online Status: See when users are online
- Profile Management: Upload and update profile pictures
- Theme Toggle: Switch between light and dark themes
- Responsive Design: Works on desktop, tablet, and mobile devices
ISC
Feel free to submit issues and pull requests.
For issues or questions, please open an issue in the repository.