A real-time chat application built with Node.js, Express, and Socket.io.
In this app :
- there are different chatrooms
- has a sidebar that displays the current room name and a live list of users currently online.
- users of a room are visible to all the users of that particular room
- when a user joins a room, the other users of that room get notified
- time is visible for all the messages : using moment
- when a user leaves, the rest of the users are notified about it
Used :
- Qs (for parsing URL parameters) -> Query string -> search qs cdn and copy the script and use it in the html file
- momentjs for the timestamps
- expressjs
- html, css
- socket.io
Key Concepts of Socket.io :
- Two-way traffic : when A sends a message, it goes to the server. The server instantly "pushes" that message to B. This happens in milliseconds because the "line" is already open.
- Event-Based : Everything in Socket.io is an Event. You name your events whatever you want:
--- socket.emit('..', data) — Sending an event.
--- socket.on('..', ...) — Listening for an event. - Broadcasting & Rooms : Socket.io has built-in "logic" that raw WebSockets don't have:
--- Broadcasting: Sending a message to everyone except the sender.
--- Rooms: Dividing users into groups (like your "JavaScript" or "Python" rooms) so messages only go to the right people.