socket.io
Real-time, bidirectional event-based communication for Node.js — WebSockets with automatic fallback, rooms, namespaces, and horizontal scaling support.
socket.io
Node.jsReal-time, bidirectional event-based communication for Node.js — WebSockets with automatic fallback, rooms, namespaces, and horizontal scaling support.
Fit
Bundle (gzip)
54.7 kB
265.2 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Building real-time features (chat, live notifications, collaborative editing) over raw WebSockets requires handling reconnection, broadcasting to groups of clients, and dealing with environments that block WebSocket connections.
What It Does
Socket.IO abstracts WebSockets with automatic HTTP long-polling fallback, built-in reconnection logic, and a rooms API for broadcasting to subsets of connected clients. Namespaces let you multiplex multiple channels over a single connection, and the adapter system enables horizontal scaling with Redis.
Installation
npm install socket.ioUsage Example
import { Server } from 'socket.io';
import { createServer } from 'http';
const httpServer = createServer();
const io = new Server(httpServer, { cors: { origin: '*' } });
io.on('connection', (socket) => {
console.log('User connected:', socket.id);
socket.on('join-room', (roomId) => socket.join(roomId));
socket.on('send-message', ({ roomId, message }) => {
io.to(roomId).emit('new-message', { from: socket.id, message });
});
socket.on('disconnect', () => console.log('User left:', socket.id));
});
httpServer.listen(3001);Related packages
Role and attribute based access control (RBAC + ABAC) for Node.js with a fluent, readable API.
bcryptjsNode.jsPure JavaScript bcrypt password hashing — no native dependencies, same API as bcrypt, works anywhere Node.js runs.
bullmqNode.jsPremium message queue and job scheduler for Node.js backed by Redis — reliable background job processing with retries, priorities, and rate limiting.
casbinNode.jsA powerful authorization library that supports RBAC, ABAC, ACL and more via configurable policy models.
dotenvNode.jsLoad environment variables from a `.env` file into `process.env` — the standard way to manage configuration in Node.js apps.