This project is a real-time chat application that allows users to communicate with each other in real time. It uses React and Socket.io for the front end and Node.js and Express for the back end.
- This app works on the principle of rooms, you can create a room on the first screen by entering your username and your own unique
room-id
and sharing the room URL with your friends/family. - Once they open the shared URL, they will be prompted to enter their
username
. - A
1 sec
sound is played when a message is sent, to improve user experience.
-
Client
- React (Vite)
- Tailwind CSS
- Socket.io (client)
The Client application is a React application that uses Socket.io to communicate with the Server.
The React Application is built using Vite
and Typescript
and styled with Tailwind CSS
.
- Server
- Socket.io
- Express (Node.js)
The Server application is a
Node.js
application that usesSocket.io
to communicate with the Client.
Handling multiple users simultaneously is a common problem in real-time applications.
- Especially when you're using web sockets.
I have used Cluster Adapter for handling concurrency.
- When scaling to
multiple Socket.IO servers
, you will need to replace the default in-memory adapter by another implementation, so theevents
andrequests
are properlyrouted
to allclients
. - Every packet that is sent to multiple clients
(e.g. io.to("room1").emit() or socket.broadcast.emit())
is also sent to other workers via the IPC channel. - The above implementation can be seen here
If you're on Linux, it's a cherry on the cake. just run the following commands:
scripts/setup.sh
scripts/server.sh
scripts/client.sh
Alternatively You may follow the below instructions if you're on Windows.
- For more details on how to install Node.js and NPM, please refer to the Node.js documentation.
- Clone the repository and run
git clone https://github.com/localhostd3veloper/realtime-chat-app
- Move to the
client
directory and install thedependencies
cd realtime-chat-app/client && npm install
- Run the Client
application
npm run dev
- Open a new terminal, move to the
server
directory and install thedependencies
cd realtime-chat-app/server && npm install
- Run the Server
application
npm run dev