A real-time chat application with two different implementations: WebSocket and Long Polling.
This repository contains two approaches to building real-time chat applications:
- WebSocket - Bidirectional persistent connection for instant messaging
- Long Polling - HTTP-based polling mechanism for message updates
Both implementations demonstrate different techniques for achieving real-time communication.
Live-Chat/
├── WebSocket/ # WebSocket-based chat with authentication
│ ├── backend/ # Express.js + WebSocket server
│ ├── frontend/ # Vite + Vanilla JS client
│ └── README.md
└── LongPolling/ # Long polling-based chat
├── backend/ # Express.js server
├── frontend/ # Vanilla JS client
└── README.md
A full-featured chat application with user authentication, message reactions, and persistent database.
Features:
- User registration and login with JWT
- Real-time messaging via WebSocket
- Message reactions (like/dislike)
- SQLite database with Knex
- Secure HTTP-only cookies
- Comprehensive error handling
Tech: Express.js, WebSocket (ws), SQLite3, Knex.js, JWT, Bcrypt
Quick Start:
cd WebSocket/backend
npm install
node migrations/init.js
node app.js
# In another terminal
cd WebSocket/frontend
npm install
npm run devOpen http://localhost:5173
A lightweight chat application using HTTP long polling for message retrieval.
Features:
- Simple user messaging
- No authentication required
- In-memory message storage
- Minimal dependencies
- Long polling mechanism with 25-second timeout
Tech: Express.js, Vanilla JavaScript
Quick Start:
cd LongPolling/backend
npm install
npm start
# Open LongPolling/frontend/index.html in browser| Feature | WebSocket | Long Polling |
|---|---|---|
| Connection Type | Persistent | HTTP polling |
| Latency | Instant | 100ms polling |
| Scalability | Requires connection management | Simpler to scale |
| Complexity | Higher | Lower |
| Database | SQLite | In-memory |
| Authentication | JWT + Bcrypt | None |
| Reactions | Yes | No |
Choose one implementation and follow the Quick Start guide above, or check individual README files in each directory for detailed documentation.
Common:
- Node.js
- Express.js
WebSocket:
- WebSocket (ws)
- SQLite3
- JWT
- Bcrypt
Long Polling:
- CORS
MIT