A real-time room-based chat platform built with the MERN stack, featuring Google OAuth authentication, dynamic room creation, and WebSocket-powered instant messaging.
- 🔐 Google OAuth Authentication - Secure sign-in with Google accounts
- 🏠 Room Creation - Create chat rooms with unique 6-character codes
- 🔗 Easy Sharing - Share room codes for instant access
- 💬 Real-time Chat - WebSocket-powered instant messaging
- 👥 Room Management - Creators can remove users, anyone can leave
- 🎨 Modern UI - Clean, responsive interface
- Frontend: React.js, Socket.io-client, Axios
- Backend: Node.js, Express.js, Socket.io
- Database: MongoDB
- Authentication: Google OAuth 2.0
- Real-time: WebSocket (Socket.io)
- Node.js (v14 or higher)
- MongoDB (local or Atlas)
- Google Cloud Console account for OAuth credentials
# Create project directory
mkdir chatnest && cd chatnest
# Copy all project files from artifacts to their respective locations
# Then run the setup script:
chmod +x setup.sh
./setup.shThe setup script will automatically install all dependencies and create configuration files.
# Create project directory
mkdir chatnest
cd chatnest
# Initialize backend
mkdir backend
cd backend
npm init -y
# Install backend dependencies
npm install express mongoose socket.io cors dotenv jsonwebtoken bcryptjs passport passport-google-oauth20 express-session
# Install backend dev dependencies
npm install --save-dev nodemon
cd ..
# Initialize frontend
npx create-react-app frontend
cd frontend
# Install frontend dependencies
npm install axios socket.io-client react-router-dom
cd ..Option A: Local MongoDB
# Install MongoDB Community Edition
# Start MongoDB service
mongod --dbpath /path/to/data/directoryOption B: MongoDB Atlas (Recommended)
- Go to MongoDB Atlas
- Create a free cluster
- Get your connection string
- Whitelist your IP address
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google+ API
- Go to Credentials → Create Credentials → OAuth Client ID
- Configure OAuth consent screen
- Create OAuth 2.0 Client ID:
- Application type: Web application
- Authorized redirect URIs:
http://localhost:5000/auth/google/callback(development)https://your-backend-url/auth/google/callback(production)
- Copy Client ID and Client Secret
Create .env file in backend directory:
PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_super_secret_jwt_key_change_this_in_production
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
CLIENT_URL=http://localhost:3000
SESSION_SECRET=your_session_secret_keyCreate .env file in frontend directory:
REACT_APP_API_URL=http://localhost:5000
REACT_APP_SOCKET_URL=http://localhost:5000chatnest/
├── backend/
│ ├── config/
│ │ └── passport.js
│ ├── models/
│ │ ├── User.js
│ │ ├── Room.js
│ │ └── Message.js
│ ├── routes/
│ │ ├── auth.js
│ │ ├── rooms.js
│ │ └── messages.js
│ ├── middleware/
│ │ └── auth.js
│ ├── utils/
│ │ └── generateRoomCode.js
│ ├── server.js
│ ├── package.json
│ └── .env
├── frontend/
│ ├── public/
│ ├── src/
│ │ ├── components/
│ │ │ ├── Home.js
│ │ │ ├── Room.js
│ │ │ ├── CreateRoom.js
│ │ │ └── JoinRoom.js
│ │ ├── context/
│ │ │ └── AuthContext.js
│ │ ├── App.js
│ │ ├── App.css
│ │ └── index.js
│ ├── package.json
│ └── .env
└── README.md
Terminal 1 - Backend:
cd backend
npm run devTerminal 2 - Frontend:
cd frontend
npm startAccess the application at http://localhost:3000
Backend:
cd backend
npm startFrontend:
cd frontend
npm run buildGET /auth/google- Initiate Google OAuthGET /auth/google/callback- OAuth callbackGET /auth/user- Get current userGET /auth/logout- Logout user
POST /api/rooms/create- Create a new roomGET /api/rooms/:roomCode- Get room detailsPOST /api/rooms/:roomCode/join- Join a roomPOST /api/rooms/:roomCode/leave- Leave a roomDELETE /api/rooms/:roomCode/remove/:userId- Remove user from roomGET /api/rooms/user/all- Get user's rooms
GET /api/messages/:roomCode- Get room messagesPOST /api/messages/:roomCode- Send message (via Socket.io)
connection- User connectsjoinRoom- User joins a roomsendMessage- Send message to roomreceiveMessage- Receive message from roomuserJoined- Notification when user joinsuserLeft- Notification when user leavesuserRemoved- Notification when user is removeddisconnect- User disconnects
- Prepare Backend for Vercel
Create vercel.json in backend directory:
{
"version": 2,
"builds": [
{
"src": "server.js",
"use": "@vercel/node"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "server.js"
}
]
}- Install Vercel CLI
npm install -g vercel- Deploy Backend
cd backend
vercel --prod- Set Environment Variables in Vercel Dashboard
- Go to your Vercel project settings
- Add all environment variables from
.env - Update
CLIENT_URLto your frontend URL
- Update Frontend Environment Variables
Update .env in frontend:
REACT_APP_API_URL=https://your-backend-url.vercel.app
REACT_APP_SOCKET_URL=https://your-backend-url.vercel.app- Deploy Frontend
cd frontend
vercel --prod-
Update Google OAuth Settings
- Go to Google Cloud Console
- Update authorized redirect URIs with production URL
- Add:
https://your-backend-url.vercel.app/auth/google/callback
-
Update Backend Environment Variables
- Update
CLIENT_URLin Vercel backend settings to your frontend URL
- Update
- Railway (recommended for Socket.io)
- Render
- Heroku
- DigitalOcean App Platform
These platforms provide better WebSocket support for real-time features.
- Go to Railway.app
- Create new project from GitHub repo
- Add environment variables
- Deploy (Railway handles WebSocket automatically)
- Get deployment URL
- Update frontend
REACT_APP_API_URLandREACT_APP_SOCKET_URL
- Sign In: Click "Sign in with Google"
- Create Room: Enter room title and click "Create Room"
- Share Code: Copy the 6-character room code
- Join Room: Others can enter the code to join
- Chat: Send messages in real-time
- Manage:
- Anyone can leave the room
- Room creators can remove users
- Creators see a "Remove" button next to each user
- JWT-based authentication
- Google OAuth 2.0 secure sign-in
- Protected API routes
- Session management
- CORS configuration
- Environment variable protection
- Private/Public room options
- File sharing
- Message reactions
- User presence indicators
- Message search
- Room descriptions
- User profiles
- Message notifications
- Dark mode
Issue: Google OAuth not working
- Check redirect URIs match exactly
- Verify Google+ API is enabled
- Check CLIENT_URL environment variable
Issue: WebSocket connection failed
- Verify SOCKET_URL matches backend URL
- Check CORS settings
- Ensure port 5000 is not blocked
Issue: MongoDB connection error
- Check MONGO_URI format
- Verify IP whitelist in Atlas
- Check database credentials
MIT License - feel free to use this project for learning and development.
For issues and questions, please open an issue on the GitHub repository.
Happy Chatting! 🎉