diff --git a/app.js b/app.js new file mode 100644 index 0000000..b2de61d --- /dev/null +++ b/app.js @@ -0,0 +1,23 @@ +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}`); +}); +