ws

A simple, blazing-fast, thoroughly tested WebSocket client and server library for Node.js.

Library
npm
v8.22.0
22,808 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
84 /100 Excellent
Development Activity 76
Maintenance 76
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
86 /100 Excellent
Architecture 87
Code Quality 88
Innovation 84
Learning Curve 85

ws is the de facto standard WebSocket implementation for Node.js, providing both client and server APIs that closely mirror the browser’s native WebSocket interface. It implements the full HyBi 07-17 WebSocket protocol drafts (RFC 6455), including the permessage-deflate compression extension, and is validated against the Autobahn test suite for both client and server conformance.

Because it has no required runtime dependencies and exposes low-level primitives like its own Sender and Receiver classes, ws is frequently used both directly by application developers building real-time features and as the underlying transport inside higher-level libraries (Socket.IO, engine.io, and many others) across the Node.js ecosystem.

What You Get

  • A WebSocket client class with an API modeled closely on the browser’s native WebSocket, including send, close, event handlers, and an EventTarget-compatible mode
  • A WebSocketServer class supporting standalone listening, attachment to existing HTTP/S servers, and manual noServer upgrade handling for routing multiple WebSocket endpoints
  • Built-in support for the permessage-deflate compression extension with fine-grained tuning options (window bits, memory level, context takeover)
  • Optional native addons (bufferutil, utf-8-validate) that are auto-detected and used to accelerate frame masking/unmasking and UTF-8 validation
  • A Node.js streams-compatible duplex wrapper (createWebSocketStream) for piping WebSocket data through the standard streams API
  • Broadcast-friendly server APIs (wss.clients) for iterating and messaging all connected clients

Common Use Cases

  • Building real-time chat, notification, or collaborative editing backends that push data to connected clients over a single persistent connection
  • Implementing low-latency game or trading-data servers where full-duplex, low-overhead messaging outperforms polling-based HTTP
  • Acting as the transport layer underneath higher-level realtime frameworks (Socket.IO, engine.io) or custom RPC-over-WebSocket protocols
  • Proxying or bridging WebSocket traffic in gateways and API servers that need to multiplex several WebSocket endpoints behind one HTTP server

Under The Hood

Architecture: ws separates concerns cleanly across lib/: websocket.js implements the client-facing WebSocket state machine (connecting, opening, handshake, close negotiation) as an EventEmitter; websocket-server.js implements WebSocketServer, handling HTTP upgrade requests, subprotocol/extension negotiation, and client bookkeeping; and the actual wire protocol is split into sender.js (frame construction, masking, optional deflate) and receiver.js (a Writable stream implemented as an explicit state machine — GET_INFO, GET_PAYLOAD_LENGTH_16/64, GET_MASK, GET_DATA, INFLATING, DEFER_EVENT — that incrementally parses HyBi frames off the incoming socket). permessage-deflate.js implements the negotiated compression extension on top of Node’s zlib, and stream.js adapts a WebSocket into a Node.js Duplex for standard streams interop. index.js composes all of these into the single exported WebSocket class with static properties attached (Server, Receiver, Sender, createWebSocketStream).

Tech Stack: Pure JavaScript targeting Node.js >=10, with zero required runtime dependencies — bufferutil and utf-8-validate are declared only as optional peer dependencies that are dynamically required if present, accelerating masking/unmasking and UTF-8 validation with native addons while falling back to pure-JS implementations otherwise. The package ships dual entry points (index.js for CommonJS require, wrapper.mjs for ESM import, browser.js as a browser-safe stub) declared via the exports map in package.json. Development tooling is ESLint 10 + Prettier for linting/formatting and Mocha + nyc for testing and coverage.

Code Quality: The test suite is extensive — 12 dedicated *.test.js files under test/ covering the receiver state machine, sender, permessage-deflate, extension negotiation, subprotocol parsing, buffer utilities, validation, the WebSocket stream wrapper, and both client and server behavior, plus a separate websocket.integration.js and Autobahn conformance runners (autobahn.js, autobahn-server.js) for full protocol-compliance testing. Source files are consistently documented with JSDoc comments on every exported class and method, private state uses a _-prefixed convention, and internal-only cross-module state uses Symbol keys (kWebSocket, kStatusCode, etc.) to avoid polluting public APIs — a deliberate, disciplined approach to encapsulation for a library operating this close to the wire.

API Design: The client API is intentionally shaped to match the browser’s native WebSocket (new WebSocket(url), .send(), .on('message', ...), readyState constants), which minimizes the learning curve for anyone who has used WebSockets in a browser and enables isomorphic wrapper packages. The 739-line doc/ws.md reference documents every constructor option, event, and method in detail, and the README leads with copy-pasteable examples for the most common scenarios (simple client, simple server, external HTTP server, multi-endpoint routing, authentication, broadcast, round-trip time, streams). Getting a minimal client or server running takes only a few lines of code with no required configuration.

Used by 116 apps in this directory

Go
47%
Apache 2.0

e2a

AI Agents · Automation

194

Give your AI agents a real, authenticated email address — with SPF/DKIM-verified inbound, HMAC-signed delivery, WebSocket fan-out, and human-in-the-loop approval built in.

View details
79
Repo Health
80
Technical
71
Dependency
Built with
Go 47%
TypeScript 27%
Python 13%
Updated 1 weeks ago
Java
34%
Apache 2.0

Enso

Analytics · Data Engineering · Low Code Platforms

7,443

A visual and textual programming platform for data prep and analysis where the node graph and the underlying Enso code are always perfectly in sync, built by an Alteryx co-founder on a GraalVM engine.

View details
57
Repo Health
90
Technical
61
Dependency
Built with
Java 34%
TypeScript 27%
Scala 26%
Updated 2 months ago
TypeScript
74%
Apache 2.0

Fern

Developer Tools

3,822

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 74%
Updated 6 days ago
TypeScript
72%
AGPL 3.0

Firecrawl

AI Development · Developer Tools

194,745

Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.

View details
89
Repo Health
83
Technical
65
Dependency
Built with
TypeScript 72%
Python 12%
Updated 6 days ago
TypeScript
62%
Other

Flowise

AI Development · Automation · Developer Tools

55,521

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
75
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 62%
JavaScript 27%
Updated 2 months ago
JavaScript
65%
Other

GDevelop

Design Tools · Developer Tools · Game Development

27,961

No-code, open-source game engine for building 2D, 3D and multiplayer games — publish to iOS, Android, Steam and the web.

View details
93
Repo Health
82
Technical
61
Dependency
Built with
JavaScript 65%
C++ 22%
TypeScript 11%
Updated 1 weeks ago
JavaScript
88%
GPL 3.0

Glass by Pickle

AI Assistants

7,604

A privacy-first desktop AI assistant that sees your screen, hears your meetings, and turns live context into structured summaries—without sending a single byte to the cloud.

View details
43
Repo Health
76
Technical
68
Dependency
Built with
JavaScript 88%
TypeScript 12%
Updated 1 years ago
Python
71%
Apache 2.0

GPT Researcher

AI Assistants · Productivity

30,269

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
90
Repo Health
91
Technical
64
Dependency
Built with
Python 71%
TypeScript 18%
Updated 2 weeks ago
TypeScript
83%
Apache 2.0

Grist

Databases · No Code Platforms

11,991

A modern relational spreadsheet that combines Python-powered formulas, drag-and-drop dashboards, and granular access controls in a self-hostable, SQLite-backed data platform.

View details
91
Repo Health
93
Technical
63
Dependency
Built with
TypeScript 83%
Python 11%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers