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-idand sharing the room URL with your friends/family. - Once they open the shared URL, they will be prompted to enter their
username. - A
1 secsound 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.jsapplication that usesSocket.ioto 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 theeventsandrequestsare properlyroutedto 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.shscripts/server.shscripts/client.shAlternatively 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
clientdirectory and install thedependencies
cd realtime-chat-app/client && npm install- Run the Client
application
npm run dev- Open a new terminal, move to the
serverdirectory and install thedependencies
cd realtime-chat-app/server && npm install- Run the Server
application
npm run dev