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.