Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
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.
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.
Libraries and code examples
ws
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.
async function start() {
/** Create WS Server */
const wsServer = new WebSocketServer({
server: httpServer,
path: '/graphql',
})
/** hand-in created schema and have the WS Server start listening */
const serverCleanup = useServer({ schema, context }, wsServer)
const server = new ApolloServer<Context>({
schema,
plugins: [
ApolloServerPluginDrainHttpServer({ httpServer }),
{
async serverWillStart() {
return {
async drainServer() {
await serverCleanup.dispose()
},
}
},
},
],
})
await server.start()
app.use('/graphql', cors<cors.CorsRequest>(), express.json(), expressMiddleware(server, { context: async () => context }));
httpServer.listen(PORT, () => {
console.log(`🚀 Server ready at http://localhost:${PORT}/graphql`)
console.log(`⏰ Subscriptions ready at http://localhost:${PORT}/graphql`)
console.log(
`⭐️ See sample queries: http://pris.ly/e/ts/graphql-subscriptions#using-the-graphql-api`,
)
})
}
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.
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.
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.
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.
public createIOServer(
port: number | undefined,
options?: ServerOptions,
): Server {
if (this.httpServer && port === 0) {
return new Server(this.httpServer, options);
}
return new Server(port, options);
}
Engine.IO
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.
function server() {
this.service = new engine.Server(Object.assign({
perMessageDeflate: !!this.primus.options.compression,
httpCompression: !!this.primus.options.compression,
maxHttpBufferSize: this.primus.options.maxLength
}, this.primus.options.transport));
// // We've received a new connection, create a new Spark. The Spark will // automatically announce it self as a new connection once it's created (after // the next tick). // this.service.on('connection', (socket) => {
const spark = new this.Spark(
socket.request.headers // HTTP request headers.
, socket.request.primus // IP Address location.
, socket.request.query // Optional query string.
, socket.id // Unique connection id.
, socket.request // Reference to the HTTP req.
, socket // Reference to the Engine.IO socket.
);
spark.on('outgoing::end', () => socket && socket.close());
spark.on('outgoing::data', (data) => socket.write(data));
socket.on('error', spark.emits('incoming::error'));
socket.on('data', spark.emits('incoming::data'));
socket.on('close', spark.emits('incoming::end', (next) => {
socket.removeAllListeners();
socket = null;
next();
}));
});
// // Listen to upgrade requests. // this.on('upgrade', (req, socket, head) => {
this.service.handleUpgrade(req, socket, head);
}).on('request', (req, res) => {
// // Engine.IO closes the handshake socket before we receive a `connection` // event. And as the socket is already answered it can be undefined. // req.primus = {
remoteAddress: req.socket.remoteAddress,
remotePort: req.socket.remotePort
};
this.service.handleRequest(req, res);
}).once('close', () => this.service.close());
}
SockJS
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.
var init = function(server, config) {
var socket = sockjs.createServer({
log: logger.log.bind(logger)
});
socket.on('connection', function(conn) {
var service = (conn.pathname.split("/"))[2];
logger.log("connection to service '"+service+"'");
if (!services[service]) {
conn.close(404, "Service not found");
return logger.error("invalid service '"+service+"'");
}
conn.do = function(method, data) {
this.write(JSON.stringify({
'method': method,
'data': data
}));
}.bind(conn);
conn.on("data", function(data) {
try {
data = JSON.parse(data);
} catch(e) {
logger.error("error parsing data:", data);
return;
}
if (data.method) {
conn.emit("do."+data.method, data.data || {});
} else {
conn.emit("message", data);
}
});
services[service].handler(conn);
});
socket.installHandlers(server, {
prefix: '^/socket/(\\w+)'
});
};
graphql-ws
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.
async function start() {
/** Create WS Server */
const wsServer = new WebSocketServer({
server: httpServer,
path: '/graphql',
})
/** hand-in created schema and have the WS Server start listening */
const serverCleanup = useServer({ schema, context }, wsServer)
const server = new ApolloServer<Context>({
schema,
plugins: [
ApolloServerPluginDrainHttpServer({ httpServer }),
{
async serverWillStart() {
return {
async drainServer() {
await serverCleanup.dispose()
},
}
},
},
],
})
await server.start()
app.use('/graphql', cors<cors.CorsRequest>(), express.json(), expressMiddleware(server, { context: async () => context }));
httpServer.listen(PORT, () => {
console.log(`🚀 Server ready at http://localhost:${PORT}/graphql`)
console.log(`⏰ Subscriptions ready at http://localhost:${PORT}/graphql`)
console.log(
`⭐️ See sample queries: http://pris.ly/e/ts/graphql-subscriptions#using-the-graphql-api`,
)
})
}
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.