A real-time chat application built using Node.js, Express, Socket.io, and Microsoft SQL Server. This project demonstrates how modern web applications handle live communication, server-side processing, and persistent data storage.
Designed as a portfolio project to demonstrate full-stack engineering skills, including WebSockets, backend architecture, and relational database integration.
- ⚡ Real-time messaging using WebSockets
- 💾 Persistent chat history stored in SQL Server
- 🌐 Multiple user support
- 🧠 Event-driven architecture
- 🔗 Client-server communication using Socket.io
- HTML
- JavaScript
- Socket.io Client
- Node.js
- Express.js
- Socket.io
- Microsoft SQL Server
chat-app
│
├── server
│ ├── server.js
│ └── db.js
│
├── client
│ ├── index.html
│ └── app.js
│
├── package.json
└── README.md
Client Browser
(index.html + app.js)
│
│ WebSocket Connection
▼
Socket.io Server
(Node.js)
│
│ SQL Queries
▼
Microsoft SQL Server
Messages Table
When a user opens the application, the browser establishes a Socket.io connection with the server.
const socket = io();This creates a persistent WebSocket channel between the client and server.
When a user submits a message:
socket.emit("chat message", { username, message });The client emits a chat message event to the server.
The backend listens for incoming messages:
socket.on("chat message", async (data) => { ... });The server:
- Receives the message
- Inserts the message into SQL Server
- Broadcasts it to all connected clients
Messages are stored in the database using SQL queries:
INSERT INTO Messages (username, message)
VALUES (@username, @message)This ensures chat history is persisted.
After saving the message, the server sends it to every connected client:
io.emit("chat message", data);This creates the real-time chat experience.
The browser dynamically updates the chat interface:
const li = document.createElement("li");
li.textContent = data.username + ": " + data.message;
messages.appendChild(li);Messages appear instantly without refreshing the page.
User Message
│
▼
Browser (Socket.io Client)
│
▼
Node.js Server
│
▼
SQL Server Database
│
▼
Broadcast to all clients
│
▼
Live Chat UI Update
npm install
node server/server.js
http://localhost:3000
Open multiple browser tabs to test real-time messaging.
Messages
----------------------------
id INT (Primary Key)
username VARCHAR(50)
message TEXT
created_at DATETIME
Possible enhancements for production-ready chat systems:
- 🔐 User authentication (JWT)
- 💬 Chat rooms
- 🟢 Online user indicators
- ⌨️ Typing indicators
- 📜 Message history loading
- 📎 File and image sharing
- 🎨 UI improvements with React or Tailwind
This project demonstrates several important software engineering concepts:
- Real-time communication with WebSockets
- Event-driven backend architecture
- Persistent data storage with relational databases
- Client-server communication patterns
- Scalable chat application design
It serves as a solid example of building a full-stack real-time system from scratch.