WebSockets with Socket.io

Socket.io allows real-time communication between clients and the server.

Snippet:

const io = require("socket.io")(3000); io.on("connection", socket => { console.log("User connected"); socket.on("message", msg => console.log(msg)); });

Example:

io.on("connection", socket => { socket.emit("welcome", "Hello, user!"); });