ws
Simple to use, blazing fast, and thoroughly tested WebSocket client and server for Node.js.
ws
Node.jsSimple to use, blazing fast, and thoroughly tested WebSocket client and server for Node.js.
Fit
Bundle (gzip)
226 B
284 B raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Node.js has no built-in WebSocket server, and implementing the protocol handshake, framing, and ping/pong keep-alive correctly by hand is impractical for real-time features like chat or live updates.
What It Does
ws provides a minimal, standards-compliant WebSocket implementation for both client and server, with a tiny API and excellent performance. Many higher-level real-time libraries are built on top of it.
Installation
npm install wsUsage Example
import { WebSocketServer } from "ws";
const wss = new WebSocketServer({ port: 8080 });
wss.on("connection", (socket) => {
socket.on("message", (data) => {
socket.send(`echo: ${data}`);
});
socket.send("connected");
});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.