npmsocket.iov4.8.3
npmIntermediate

socket.io

node.js realtime framework server

websocketrealtimeeventschatmultiplayerframeworktcpsocketiojavascript
The Problem

Raw WebSockets require you to handle reconnection, event multiplexing, room management, binary data, and fallback for environments that don't support WebSockets. Socket.IO was built to make real-time bidirectional communication reliable across browsers, mobile clients, and servers without managing any of that yourself.

Mental Model

Socket.IO is an event emitter over the network. On the server: io.on('connection', socket => socket.on('message', data => io.emit('message', data))). On the client: socket.on('message', data => ...) and socket.emit('message', data). Both sides emit and listen to named events. Rooms let you broadcast to subsets of clients.

60-second start

Installation

// with npm
npm install socket.io

// with yarn
yarn add socket.io

Use it when

Use Socket.IO for chat applications, live collaboration, real-time dashboards, multiplayer games, or any feature where the server needs to push updates to clients. The automatic reconnection and room system make it production-ready out of the box.

Skip it when

Socket.IO's abstraction layer adds overhead โ€” if you're communicating between services where you control both ends, raw WebSockets or Server-Sent Events (for one-way) are lighter. For very high throughput (millions of concurrent connections), the overhead of Socket.IO's protocol becomes meaningful.

Alternatives
wsRaw WebSocket library โ€” faster and lighter; use it when you control both client and server and don't need rooms/namespaces
partykitManaged WebSocket infrastructure โ€” abstracts servers entirely; good for collaborative features without ops
ablyManaged real-time messaging platform โ€” offloads infra entirely at the cost of vendor lock-in

Ready to explore the full API?

See every class, function, and relationship in an interactive graph.