Visitor / server.js
clone3's picture
Update server.js
df83c50 verified
raw
history blame
714 Bytes
const express = require('express');
const http = require('http');
const socketIo = require('socket.io');
const app = express();
const server = http.createServer(app);
const io = socketIo(server);
let visitorCount = 0;
app.get('/', (req, res) => {
res.json({ message: 'WebSocket server is running', visitorCount });
});
io.on('connection', (socket) => {
visitorCount++;
io.emit('visitorCount', visitorCount);
socket.on('disconnect', () => {
visitorCount--;
io.emit('visitorCount', visitorCount);
});
});
const PORT = process.env.PORT || 7860; // Default to 7860 for Hugging Face
server.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});