JavaScript WebSocket libraries

Updated Nov 2026

JavaScript WebSocket libraries keep one connection open between a server and its clients, and either side can send a message over it at any time. These libraries let chat apps, live dashboards, and AI agents push updates to clients as they happen, without the client polling the server.

Popularity

ws has the most monthly downloads in this comparison, at 1.5B.

LibraryMonthly downloadsStarsLast releaseLicense
ws
1.5B
22.8KNov 2026MIT
faye-websocket
156.8M
612Nov 2026Apache-2.0
websocket-driver
155.4M
111Nov 2026Apache-2.0
crossws
129.6M
745Oct 2026MIT
Socket.IO
100.0M
63.3KSep 2026MIT
Engine.IO
97.4M
63.3KSep 2026MIT
SockJS
65.9M
2.1KDec 2021MIT
graphql-ws
63.9M
1.9KNov 2026MIT
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

ws implements WebSocket clients and servers for Node.js and passes the Autobahn protocol test suite. A WebSocketServer listens on its own port or shares an existing HTTP server, and each connection emits a message event and sends with send, for text or binary data. The library runs only in Node.js: in the browser, the built-in WebSocket object connects to a ws server directly. Compression through the permessage-deflate extension is off by default on the server, because it costs speed and memory.

Downloads / mo
1.5B
Stars
22.8K
Last release
8.23.0
License
MIT

Strengths

  • Works with standard WebSocket clients. Browsers connect with their built-in WebSocket object.
  • Shares an existing HTTP server. Handles WebSocket upgrades on the same HTTP server as the app.

Limitations

  • Browser clients need another API. In the browser, the native WebSocket object takes its place.
  • Compression adds memory overhead. The permessage-deflate extension costs speed and memory, so it's off by default on the server.

Quickstart

From README.md
$ npm install ws@8.23.0
import { WebSocketServer } from "ws";
const server = new WebSocketServer({ port: 8080 });
server.on("connection", (socket) => socket.send("Hello"));

ws examples

From open-source projects on GitHub

faye-websocket

faye-websocket handles WebSocket connections inside an existing Node.js HTTP server, using the same API that browsers expose. The app listens for the server's upgrade event, checks the request with WebSocket.isWebSocket, and creates a socket that emits message and close events and sends with send. The package also includes a WebSocket client and an EventSource handler for one-way server push over plain HTTP. It came out of the Faye messaging project and contains no server of its own.

Downloads / mo
156.8M
Stars
612
Last release
0.12.0
License
Apache-2.0

Strengths

  • Standard WebSocket API. Sockets expose the same send, message, and close interface as the browser's WebSocket.
  • Handles EventSource too. One-way EventSource streams push data to clients over plain HTTP.

Limitations

  • No server of its own. The app's HTTP server passes each upgrade request to the library.

Quickstart

From README.md
$ npm install faye-websocket@0.12.0
const http = require("node:http");
const WebSocket = require("faye-websocket");
const server = http.createServer();
server.on("upgrade", (request, socket, head) => {
  if (!WebSocket.isWebSocket(request)) return socket.destroy();
  const connection = new WebSocket(request, socket, head);
  connection.send("Hello");
});
server.listen(8080);

faye-websocket examples

From open-source projects on GitHub

websocket-driver

websocket-driver implements the WebSocket protocol without doing any input or output itself, so it runs over any stream the app supplies. The driver selects the right protocol version for each client, performs the opening and closing handshakes, recombines fragmented messages, and answers ping frames with pongs. The app pipes bytes from a TCP socket or HTTP upgrade into the driver and writes the bytes it produces back out. faye-websocket is built on top of it.

Downloads / mo
155.4M
Stars
111
Last release
0.8.0
License
Apache-2.0

Strengths

  • Works over any stream. The app moves bytes in and out, and the driver handles the protocol.
  • Answers pings itself. Replies to ping frames, recombines fragments, and runs the closing handshake.

Quickstart

From README.md
$ npm install websocket-driver@0.8.0
const http = require("node:http");
const websocket = require("websocket-driver");
const server = http.createServer();
server.on("upgrade", (request, socket, head) => {
  if (!websocket.isWebSocket(request)) return socket.destroy();
  const driver = websocket.http(request);
  driver.io.write(head);
  socket.pipe(driver.io).pipe(socket);
  driver.start();
  driver.text("Hello");
});
server.listen(8080);

websocket-driver examples

From open-source projects on GitHub

crossws defines one set of WebSocket server hooks, such as open, message, and close, and runs them on Node.js, Bun, Deno, and Cloudflare Workers through an adapter for each runtime. Each hook receives a peer object that sends messages and can subscribe to topics for publish and subscribe. The Node.js adapter ships with ws built in, and a separate adapter uses uWebSockets.

Downloads / mo
129.6M
Stars
745
Last release
0.4.17
License
MIT

Strengths

  • One API on four runtimes. The same hooks run on Node.js, Bun, Deno, and Cloudflare Workers through adapters.
  • Bundles ws for Node.js. The Node.js adapter ships with ws, and a uWebSockets adapter is also available.

Quickstart

From node.md
$ npm install crossws@0.4.17
import { createServer } from "node:http";
import crossws from "crossws/adapters/node";
const adapter = crossws({ hooks: { open(peer) { peer.send("Hello"); } } });
const server = createServer((request, response) => response.end("WebSocket server"));
server.on("upgrade", (request, socket, head) => adapter.handleUpgrade(request, socket, head));
server.listen(8080);

crossws examples

From open-source projects on GitHub

Socket.IO sends named events between a server and its clients, such as socket.emit('hello', 'world'), with optional acknowledgements that work like callbacks. A connection starts over HTTP long-polling and upgrades to WebSocket when the network allows it. Sockets can join rooms, and a broadcast to a room reaches every socket in it. Socket.IO uses its own protocol on top of WebSocket, so browsers connect with the Socket.IO client library rather than the built-in WebSocket object.

Downloads / mo
100.0M
Stars
63.3K
Last release
4.8.4
License
MIT

Strengths

  • Falls back to HTTP polling. Event connections keep working when a network blocks WebSocket.
  • Broadcasts to selected groups. Rooms send events to a chosen group of connected clients.

Limitations

  • Requires a Socket.IO client. A plain WebSocket client cannot connect to a Socket.IO server.
  • Missed events need application storage. Server events sent during a disconnect are lost unless the app stores them.

Quickstart

From README.md
$ npm install socket.io@4.8.4
import { Server } from "socket.io";
const server = new Server(3000);
server.on("connection", (socket) => socket.emit("hello", "world"));

Socket.IO examples

From open-source projects on GitHub

Engine.IO is the transport layer underneath Socket.IO. It opens a two-way connection between a Node.js server and a client over HTTP long-polling first, then upgrades to WebSocket or WebTransport when possible. engine.attach adds it to an existing HTTP server, and each connection emits message events and sends with send. It has no rooms or named events, which Socket.IO adds on top, and its code now lives in the Socket.IO monorepo.

Downloads / mo
97.4M
Stars
63.3K
Last release
6.6.11
License
MIT

Strengths

  • Starts on long-polling. Connections open over HTTP, then upgrade to WebSocket or WebTransport when they can.

Quickstart

From README.md
$ npm install engine.io@6.6.11
const http = require("node:http");
const engine = require("engine.io");
const server = http.createServer();
const transport = engine.attach(server);
transport.on("connection", (socket) => socket.send("Hello"));
server.listen(8080);

Engine.IO examples

From open-source projects on GitHub

SockJS-node is the Node.js server for SockJS, a protocol that gives browsers a WebSocket-like object even where WebSocket is blocked. The SockJS client in the browser tries WebSocket first and falls back to HTTP streaming or polling. On the server, sockjs.createServer returns a server whose installHandlers call mounts it under a URL prefix on an existing HTTP server. Each connection emits data events and sends with write, which takes strings only.

Downloads / mo
65.9M
Stars
2.1K
Last release
0.3.24
License
MIT

Strengths

  • Works without WebSocket transport. The browser gets a WebSocket-like connection over fallback transports.
  • Shares an existing HTTP server. Handlers install under a URL prefix next to other HTTP handlers.

Limitations

  • Messages must be strings. Structured or binary data has to be encoded as text before write.
  • Multiple servers need session affinity. Every request in a session has to reach the same server.

Quickstart

From README.md
$ npm install sockjs@0.3.24
var http = require('http');
var sockjs = require('sockjs');

var echo = sockjs.createServer();
echo.on('connection', function(conn) {
    conn.on('data', function(message) {
        conn.write(message);
    });
    conn.on('close', function() {});
});

var server = http.createServer();
echo.installHandlers(server, {prefix:'/echo'});
server.listen(9999, '0.0.0.0');

SockJS examples

From open-source projects on GitHub

graphql-ws implements the GraphQL over WebSocket Protocol, which carries GraphQL queries, mutations, and subscriptions over one WebSocket connection. On the server, useServer attaches a GraphQL schema to a ws server, and the client side calls createClient with the server's URL. The package has no dependencies. It is not compatible with the deprecated subscriptions-transport-ws protocol, so the server and every client have to use it.

Downloads / mo
63.9M
Stars
1.9K
Last release
6.4.3
License
MIT

Strengths

  • No dependencies. One package holds both the server and the client for the protocol.

Limitations

  • Separate from the old protocol. Clients built on subscriptions-transport-ws can't connect, so both sides have to switch.

Quickstart

From ws.ts
$ npm install graphql-ws@6.4.3 ws@8.23.0 graphql@16
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from "graphql";
import { WebSocketServer } from "ws";
import { useServer } from "graphql-ws/use/ws";
const schema = new GraphQLSchema({ query: new GraphQLObjectType({ name: "Query", fields: { hello: { type: GraphQLString, resolve: () => "Hello" } } }) });
useServer({ schema }, new WebSocketServer({ port: 4000 }));

graphql-ws examples

From open-source projects on GitHub

FAQ

For a plain WebSocket server in Node.js, use ws, which browsers reach through their built-in WebSocket object. For rooms, broadcasts, and fallback to HTTP long-polling, use Socket.IO with its client library. For one server that runs on Node.js, Bun, Deno, and Cloudflare Workers, use crossws, and for GraphQL subscriptions, graphql-ws.

Install ws, create a WebSocketServer on a port, and listen for its connection event. Each connection's send method writes a message, and its message event fires for every message the client sends.

ws implements the WebSocket protocol, so any WebSocket client can connect, including the browser's built-in one. Socket.IO adds its own protocol on top, with rooms, acknowledgements, and fallback to HTTP long-polling, and only a Socket.IO client can connect to its server.

graphql-ws implements the GraphQL over WebSocket Protocol for both server and client, with no dependencies. It isn't compatible with the deprecated subscriptions-transport-ws package, so the server and the client both have to use it.

Both fall back to HTTP transports when WebSocket is unavailable. SockJS gives the browser a WebSocket-like object and sends text messages only. Socket.IO sends named events and adds rooms and acknowledgements.

Yes, while HTTP long-polling is on: every request in a session has to reach the server that started it. Turning long-polling off and using WebSocket only removes that requirement.

For coding agents

Found your WebSocket library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official