This is a real-time chat application built using the MERN stack (MongoDB, Express.js, React, Node.js) with TailwindCSS for styling. The application allows users to register, log in, send, and receive messages in real-time.
- User registration and authentication
- Real-time messaging using Socket.IO
- Display a list of registered users
- Individual chat with any registered user
- Persistent message storage with MongoDB
- Frontend: React, TailwindCSS, Axios, Socket.IO Client
- Backend: Node.js, Express.js, MongoDB, Mongoose, Socket.IO
- Node.js
- MongoDB
Make sure you have Node.js and MongoDB installed on your machine.
-
Clone the repository
git clone [https://github.com/your-username/real-time-chat-app.git](https://github.com/HamzaAshfaq01/chat-app) cd chat-app
-
Install backend dependencies
root folder (chat-app) npm install
-
Install frontend dependencies
cd ./client npm install
-
Set up environment variables
Create a
.env
file in theroot(chat-app)
directory and add the following:PORT=5000 MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret
-
Start the backend server
go to root directory (chat-app) npm run server
-
Start the frontend development server
cd ./client npm run dev
-
Open your browser and navigate to
http://localhost:3000
-
Register a new user
POST /api/auth/register
-
Login a user
POST /api/auth/login
-
Retrieve the last 50 messages
GET /api/messages/:userId
-
Send a new message
POST /api/messages
- Retrieve all users
GET /api/users
-
join
- Emitted by the client to join a specific room.
- Payload:
userId
-
sendMessage
- Emitted by the client to send a message.
- Payload:
message
-
receiveMessage
- Emitted by the server to send a received message to the client.
- Payload:
message
- Register and Login: Create a new account and log in using the registration and login forms.
- Chat: Click on any registered user from the list to start a chat. Type your message and hit send to communicate in real-time.
This project is licensed under the MIT License.