This guide will help you get the Chat App project up and running on your local machine.
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher) - Download
- npm (comes with Node.js) or yarn
- git (optional but recommended)
- A modern web browser (Chrome, Firefox, Safari, Edge)
node --version # Should show v14.0.0 or higher
npm --version # Should show 6.0.0 or higherThis project contains two implementations of a real-time chat application:
- Long-Polling - Traditional HTTP-based polling
- WebSockets - Persistent WebSocket connections
Using Git:
git clone <repository-url>
cd Chat-AppManual Download:
- Download the ZIP file
- Extract it to your desired location
- Open terminal/command prompt in the extracted folder
npm installThis installs dependencies listed in the root package.json.
Terminal 1 - Start Backend Server:
cd Long-Polling/backend
npm install # Only needed first time
node server.jsExpected output:
Server running at http://localhost:3000
Terminal 2 - Open Frontend in Browser:
Method 1: Direct file access
file:///absolute/path/to/Chat-App/Long-Polling/frontend/index.html
Method 2: Using Python's built-in server
cd Long-Polling/frontend
python3 -m http.server 8000
# Then open: http://localhost:8000Terminal 1 - Start Backend Server:
cd WebSockets/backend
npm install # Only needed first time
node sever.jsExpected output:
Server running at http://localhost:3000
Terminal 2 - Open Frontend in Browser:
Method 1: Direct file access
file:///absolute/path/to/Chat-App/WebSockets/frontend/index.html
Method 2: Using Python's built-in server
cd WebSockets/frontend
python3 -m http.server 8000
# Then open: http://localhost:8000To test both implementations side-by-side:
- Start Long-Polling server on port 3000
- Open Long-Polling frontend in Browser Tab 1
- Open a new terminal window
- Stop the Long-Polling server (Ctrl+C)
- Start WebSockets server on port 3000
- Open WebSockets frontend in Browser Tab 2
- Send messages in both tabs to see the difference
.
├── package.json # Root project config
├── README # Main documentation
├── SETUP.md # This file
├── CONTRIBUTING.md # Contribution guidelines
├── ARCHITECTURE.md # Architecture overview
│
├── Long-Polling/ # Long-polling implementation
│ ├── README.md # Implementation-specific docs
│ ├── backend/
│ │ └── server.js # Express server with polling
│ └── frontend/
│ ├── index.html # Chat interface
│ └── script.js # Polling logic
│
└── WebSockets/ # WebSocket implementation
├── README.md # Implementation-specific docs
├── package.json # Dependencies
├── backend/
│ ├── package.json # Backend config
│ └── sever.js # Express + WebSocket server
└── frontend/
├── index.html # Chat interface
└── script.js # WebSocket logic
Solution: Kill the process using port 3000
macOS/Linux:
lsof -ti:3000 | xargs kill -9Windows:
netstat -ano | findstr :3000
taskkill /PID <PID> /FAlternative: Change the port in the server file
Solution: Install dependencies
cd <backend-folder>
npm install
npm list # Verify packages are installedSolution: Ensure the backend server is running on http://localhost:3000
Check server output - should show:
Server running at http://localhost:3000
Solution:
- Verify backend is running
- Check that you're using the correct port (3000)
- Try a different browser in case of browser compatibility issues
Solution: Use one of two methods:
- Direct file access - Open index.html directly in browser
- Local server - Use Python's built-in HTTP server:
cd frontend python3 -m http.server 8000
Backend - Add to server.js:
app.use((req, res, next) => {
console.log(`${req.method} ${req.path}`);
next();
});Frontend - Add to script.js:
// Add console.logs in key functions
console.log('Sending message:', message);
console.log('Received message:', data);- VS Code REST Client - Test API endpoints directly
- Thunder Client - Alternative REST client
- Postman - Full-featured API testing
# Get all messages
curl http://localhost:3000/messages
# Send a message
curl -X POST http://localhost:3000/messages \
-H "Content-Type: application/json" \
-d '{"message":"Hello World"}'
# Like a message (WebSockets only)
curl -X POST http://localhost:3000/like \
-H "Content-Type: application/json" \
-d '{"timestamp":"2024-01-15T10:30:00.000Z"}'- Read the main README for feature overview
- Check Long-Polling README for polling details
- Check WebSockets README for WebSocket details
- Review CONTRIBUTING.md for how to contribute
- Check ARCHITECTURE.md for design details
- Keep both implementations running in separate terminals
- Use browser DevTools to monitor Network and Console tabs
- Monitor server logs for request patterns
- Test with multiple browser tabs open
- Test with browser DevTools throttling enabled
- Test with different network speeds
If you encounter issues:
- Check the troubleshooting section above
- Review the server console output for errors
- Check browser console (F12) for JavaScript errors
- Verify all files are in the correct location
- Ensure Node.js and npm are properly installed
Ready to go? Choose one of the implementations and follow the "Running the Applications" section above!