const express = require('express'); const http = require('http'); const socketIo = require('socket.io'); // Create an Express application const app = express(); const server = http.createServer(app); const io = socketIo(server); // Serve static files from the "public" directory app.use(express.static('public')); // Listen for incoming connections io.on('connection', (socket) => { console.log('A user connected'); // Listen for chat messages socket.on('chat message', (msg) => { io.emit('chat message', msg); // Broadcast the message to all clients }); // Handle disconnection socket.on('disconnect', () => { console.log('A user disconnected'); }); }); // Start the server const PORT = process.env.PORT || 7860; server.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); });