A simple real-time chat application built with Socket.IO, Express, and Node.js to demonstrate the core features of Socket.IO.
- Real-time bidirectional communication
- User join/leave notifications
- Typing indicators
- Message broadcasting
- Clean, responsive UI
- Connection Events: Handling connect, disconnect, and reconnection
- Emitting Events: Sending data between client and server
- Broadcasting: Sending messages to all connected clients
- Rooms: (Not implemented in this basic version, but mentioned in the sidebar)
- Namespaces: (Not implemented in this basic version)
- Clone this repository
- Install dependencies:
npm install - Start the server:
node server.js - Open your browser and navigate to
http://localhost:3000
The server uses Express to serve static files and Socket.IO to handle real-time communication:
- Sets up an Express server and initializes Socket.IO
- Handles connection events
- Processes incoming messages and broadcasts them to all clients
- Manages typing indicators
The client connects to the Socket.IO server and:
- Handles user interface interactions
- Emits events to the server (messages, typing)
- Listens for events from the server (messages from other users)
- Updates the UI in real-time
├── server.js # Server-side code
├── package.json # Project dependencies
├── public/ # Client-side files
│ ├── index.html # Main HTML file
│ ├── styles.css # CSS styles
│ └── main.js # Client-side JavaScript
└── README.md # This file
Here are some ideas to extend this basic chat application:
- Add user authentication
- Implement private messaging
- Create chat rooms
- Add file sharing capabilities
- Store chat history in a database
- Add emoji support
- Implement read receipts
MIT