1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-31 06:18:07 +00:00
_/socketio/src/index.js

20 lines
490 B
JavaScript
Raw Normal View History

2020-03-24 19:14:25 +09:00
// @ts-check
const path = require("path");
const app = require("express")();
const http = require("http").createServer(app);
const io = require("socket.io")(http);
const port = Number(process.env.PORT) || 8080;
app.get("/", function(_, res) {
res.sendFile(path.join(__dirname, "public", "index.html"));
});
http.listen(port, function() {
console.log(`listening on http://localhost:${port}`);
});
io.on("connect", socket => {
socket.on("message", message => io.send(message));
});