index.js 407 B

123456789101112131415161718
  1. var app = require("express")();
  2. var http = require("http").createServer(app);
  3. var io = require("socket.io")(http);
  4. app.get("/", (req, res) => {
  5. res.sendFile(__dirname + "/index.html");
  6. });
  7. io.on("connection", (socket) => {
  8. socket.on("chat message", (msg) => {
  9. console.log("message: " + msg);
  10. io.emit("chat message", msg);
  11. });
  12. });
  13. http.listen(3000, () => {
  14. console.log("listening on *:3000");
  15. });