Socket.io enables real-time bidirectional communication between client and server.
Getting Started
What is Node.js?
Modules & NPM
Modules & NPM
Process & Environment
Process & Environment Variables
Caching & Performance
Redis Caching
GraphQL with Node.js
GraphQL Basics
Node.js
Intermediate
FREE
Socket.io
Lesson 1 of 17
Intermediate
Interactive
Syntax
NODEJS
const io = require('socket.io')(server); io.on('connection', (socket) => { socket.on('message', (data) => { io.emit('message', data); }); });
Socket.io Real-time
NODE
const express = require("express"); const http = require("http"); const { Server } = require("socket.io"); const app = express(); const server = http.createServer(app); const io = new Server(server); io.on("connection", (socket) => { console.log("User connected:", socket.id); socket.on("chat message", (msg) => { io.emit("chat message", msg); }); socket.on("disconnect", () => { console.log("User disconnected"); }); }); server.listen(3000);