1 const express = require('express');
3 const http = require('http');
4 const server = http.createServer(app);
5 const { Server } = require("socket.io");
6 const io = new Server(server);
11 app.get('/index.html', (req, res) => {
12 res.sendFile(__dirname + '/index.html');
15 io.on('connection', (socket) => {
16 // Replay old comments to a newly-joining client
17 comments.forEach((comment) => {
18 socket.emit('comment', comment)
20 // When any client comments, send that to all clients (including sender)
21 socket.on('comment', (comment) => {
22 io.emit('comment', comment);
23 comments.push(comment);
27 server.listen(port, () => {
28 console.log(`listening on *:${port}`);