Newer
Older
2024-Yuma / app.js
@c1221856 c1221856 on 7 Nov 2024 548 bytes add file
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);

// このように書くことで`public/script.js`にアクセスできる
app.use(express.static('websocket'));

io.on('connection', (socket) => {
  socket.on('chat message', (msg) => {
    io.emit('chat message', msg);
  });
});

const PORT = 3000;

server.listen(PORT, () => {
  console.log(`Server is running on http://localhost:${8888}`);
});