A lightweight, real‑time chat application built with Socket.IO, Express, and MongoDB.
Users can join the room, see who’s online, and send messages that are instantly broadcast to everyone—all with persistent history.
- Real‑time messaging via Socket.IO
- Live online user tracking
- Persistent chat history stored in MongoDB
- Automatic online/offline status updates
- Clean, responsive UI with vanilla HTML/CSS/JS
- Instant delivery to all connected clients
Real-Time-chatroom-application-using-WebSockets/
├── client/
│ ├── index.html # Main HTML UI
│ ├── index.js # Client-side Socket.IO logic
│ └── styles.css # Stylesheet
├── models/
│ ├── Message.js # Mongoose schema for messages
│ └── User.js # Mongoose schema for users
├── server.js # Express & Socket.IO server
├── package.json # Dependencies & scripts
└── README.md # ← you are here!
Frontend
HTML5 · CSS3 · Vanilla JavaScript · Socket.IO Client
Backend
Node.js · Express.js · Socket.IO Server · MongoDB + Mongoose
Make sure you have the following installed:
-
Clone the repository
git clone https://github.com/ArnavVivek13/Real-Time-chatroom-application-using-WebSockets.git cd chatty -
Install dependencies
npm install
-
Configure environment variables
Create a
.envfile in the project root:MONGO_URI=mongodb://localhost:27017/chatty PORT=5000
For Atlas:
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/chatty -
Start the server
node server.js
-
Open the app
Visit:
http://localhost:5000
{
username: { type: String, required: true, unique: true },
status: { type: Boolean, required: true } // true = online
}{
user: { type: String, required: true },
message: { type: String, required: true }
}, { timestamps: true }| Event | Payload | Description |
|---|---|---|
adduser |
{ username: String } |
Register/set user online |
message |
{ text: String } |
Send a chat message |
disconnect |
— | Fired when connection closes |
| Event | Payload | Description |
|---|---|---|
users |
Array<User> |
Updated online user list |
history |
Array<Message> |
Full message history on connect |
message |
Message |
Broadcast a new chat message |
- Client connects → server sends history.
- Username submitted → server updates/creates user and broadcasts user list.
- Messages emit → server saves & broadcasts to everyone.
This project is licensed under the MIT License.
Have ideas for rooms, authentication, or deployment? Contributions welcome!