socket.io
Socket.IO is a library that enables low-latency, bidirectional, and event-based communication between a client and server. Built on top of the WebSocket protoco…
Installation
npm install socket.io
yarn add socket.io
pnpm add socket.io
Import
import { Server } from 'socket.io';Quick Example
import { Server } from 'socket.io';
import { createServer } from 'http';
const httpServer = createServer();
const io = new Server(httpServer);
io.on('connection', (socket) => {
socket.on('message', (data) => {
io.emit('message', data);
});
});
httpServer.listen(3000);About socket.io
Socket.IO is a library that enables low-latency, bidirectional, and event-based communication between a client and server. Built on top of the WebSocket protocol with fallbacks to HTTP long-polling, Socket.IO provides reliable real-time connectivity even in environments where WebSockets are blocked by firewalls or proxies. The library features automatic reconnection with exponential backoff, room and namespace support for organizing connections, binary data streaming, multiplexing over a single connection, and acknowledgement callbacks for confirming message delivery. Socket.IO's API is event-driven — both server and client emit and listen for named events with arbitrary data payloads, making it intuitive to build chat applications, live dashboards, collaborative editing tools, and multiplayer games. The server library works with Node.js HTTP servers, Express, Fastify, and Koa, while client libraries are available for JavaScript, Swift, Java, Kotlin, C++, and Dart. Socket.IO includes built-in adapter support for scaling horizontally across multiple server instances using Redis, MongoDB, or PostgreSQL as a message broker.
Quick Facts
| Package | socket.io |
| Category | HTTP |
| Weekly Downloads | 6M+ |
| License | MIT |
| Install | npm install socket.io |
Related Packages
ws is the most widely used WebSocket implementation for Node.js, providing a simple, fast, and thoro…
Express is the most widely used web application framework for Node.js, providing a minimal and flexi…
Feathers is a lightweight web framework for creating real-time applications and REST APIs using Type…
redis (node-redis) is the official Redis client for Node.js, providing a full-featured interface to …
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.