🌐
HTTP6M+/wkMIT

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
npm install socket.io
yarn
yarn add socket.io
pnpm
pnpm add socket.io

Import

ESM
import { Server } from 'socket.io';

Quick Example

usage
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

Packagesocket.io
CategoryHTTP
Weekly Downloads6M+
LicenseMIT
Installnpm install socket.io

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.