A full-featured real-time chat application built with Node.js, Socket.IO, MongoDB, and Docker. Features include real-time messaging, file sharing with streaming downloads, user presence indicators, and typing notifications.
- Real-time Messaging: Instant message delivery using Socket.IO
- File Sharing: Upload and download files with streaming support
- User Presence: See who's online and when they last seen
- Typing Indicators: Real-time typing notifications
- Message History: Persistent message storage in MongoDB
- Responsive Design: Works on desktop and mobile devices
- Docker Support: Easy deployment with Docker and Docker Compose
- Production Ready: Nginx reverse proxy and SSL support
- Backend: Node.js, Express.js
- Real-time Communication: Socket.IO
- Database: MongoDB with Mongoose ODM
- Frontend: Vanilla JavaScript, HTML5, CSS3
- File Handling: Multer for uploads, streaming for downloads
- Containerization: Docker & Docker Compose
- Reverse Proxy: Nginx
- Deployment: DigitalOcean ready
- Node.js (v16 or higher)
- MongoDB (v4.4 or higher)
- Docker & Docker Compose (optional)
-
Clone the repository
git clone <repository-url> cd realtime-chat-streaming
-
Install dependencies
npm install
-
Set up environment variables
cp .env.example .env
Edit
.envfile with your configuration. -
Start MongoDB Make sure MongoDB is running on your system.
-
Run the application
# Development mode with auto-restart npm run dev # Production mode npm start
-
Access the application Open your browser and go to
http://localhost:3000
-
Build and run with Docker Compose
docker-compose up -d
-
Access the application Open your browser and go to
http://localhost
- Create a new Ubuntu 20.04 droplet
- Choose appropriate size (minimum 1GB RAM recommended)
- Add your SSH key
# Update the system
sudo apt update && sudo apt upgrade -y
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# Reboot to apply Docker group changes
sudo reboot# Clone your repository
git clone <your-repository-url>
cd realtime-chat-streaming
# Set up environment variables for production
cp .env.example .env
nano .env # Edit with production values
# Start the application
docker-compose up -d- Point your domain to the droplet's IP address
- Install Certbot for Let's Encrypt SSL:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.comrealtime-chat-streaming/
βββ public/
β βββ index.html # Frontend application
βββ uploads/ # File upload directory
βββ .env.example # Environment variables template
βββ .gitignore # Git ignore rules
βββ docker-compose.yml # Docker Compose configuration
βββ Dockerfile # Docker image configuration
βββ nginx.conf # Nginx reverse proxy config
βββ package.json # Node.js dependencies
βββ server.js # Main application server
βββ README.md # This file
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 3000 |
NODE_ENV |
Environment | development |
MONGODB_URI |
MongoDB connection string | mongodb://localhost:27017/chat-app |
JWT_SECRET |
JWT signing secret | Required for auth |
MAX_FILE_SIZE |
Maximum file upload size | 10485760 (10MB) |
- Maximum file size: 10MB (configurable)
- Supported file types: All types
- Storage: Local filesystem (can be extended to cloud storage)
- Instant message delivery using WebSocket connections
- Message persistence in MongoDB
- Message history loading for new users
- Drag & drop file uploads
- Progress indicators during upload
- Streaming downloads with range request support
- File type detection and icons
- Responsive design for all screen sizes
- Typing indicators
- User presence (online/offline status)
- Message timestamps
- Auto-scrolling message container
- Rate limiting on API endpoints
- File size restrictions
- Input sanitization
- CORS configuration
- Nginx reverse proxy for production
- Input validation and sanitization
- File upload restrictions
- Rate limiting
- CORS configuration
- Environment variable protection
- Non-root Docker user
- Open multiple browser tabs/windows
- Enter different usernames
- Test messaging between users
- Test file upload and download
- Test typing indicators
- Test user presence indicators
Use tools like Artillery or WebSocket King to test concurrent connections:
# Install Artillery
npm install -g artillery
# Run load test (create artillery-config.yml first)
artillery run artillery-config.yml- MongoDB connection status
- WebSocket connection count
- File upload/download metrics
- Error logging
- Droplet CPU and memory usage
- Disk space monitoring
- Network traffic
- Docker container health
# Pull latest changes
git pull origin main
# Rebuild and restart containers
docker-compose down
docker-compose up -d --build# Create MongoDB backup
docker exec -it <mongo-container-id> mongodump --db chat-app --out /backup
# Restore MongoDB backup
docker exec -it <mongo-container-id> mongorestore --db chat-app /backup/chat-app- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
-
MongoDB Connection Error
- Check if MongoDB is running
- Verify MONGODB_URI in .env file
- Check network connectivity
-
File Upload Issues
- Check uploads directory permissions
- Verify MAX_FILE_SIZE setting
- Check disk space
-
WebSocket Connection Issues
- Check firewall settings
- Verify port 3000 is accessible
- Check CORS configuration
-
Docker Issues
- Ensure Docker is running
- Check Docker Compose version
- Verify port conflicts
# View application logs
docker-compose logs app
# View MongoDB logs
docker-compose logs mongo
# View Nginx logs
docker-compose logs nginx
# Follow logs in real-time
docker-compose logs -fIf you encounter any issues or have questions, please:
- Check the troubleshooting section
- Search existing issues
- Create a new issue with detailed information
- Join our community discussions
Happy Chatting! π