Faye-WebSocket is a standards-compliant WebSocket server and client library designed for Node.js environments. Extracted from the larger Faye project, it provides a low-level, event-driven API for handling WebSocket connections (RFC 6455) and EventSource streams. Unlike a full WebSocket server, it integrates with existing Node.js HTTP servers by listening for 'upgrade' events. The latest stable version, 0.11.4, was published in May 2021. The project appears to be largely unmaintained and is considered inactive, with no new versions or significant development in the past five years. Its primary differentiation lies in providing a direct implementation of the WebSocket API without significant higher-level abstractions, allowing developers fine-grained control over the protocol.
npm install faye-websocketVerified import paths — ran on the pinned version, not inferred.
This example demonstrates both a basic Faye-WebSocket server that echoes messages and a client that connects to it, sends a message, and closes.
Review Apache 2.0 license terms for compatibility with your project's licensing and obligations.
Ensure the WebSocket server presents a valid, trusted SSL/TLS certificate. For development or specific scenarios, you can optionally disable certificate verification via the `tls` option in `WebSocket.Client` constructor, though this is not recommended for production.
Implement application-level heartbeats (ping/pong) to actively monitor connection liveness. The `ws.ping()` method can be used on the server, and the client should respond with a pong. Alternatively, set a `ping` option during server-side WebSocket construction.
Consider migrating to an actively maintained WebSocket library that provides native ESM support, such as `ws`. If continuing to use `faye-websocket`, explicitly use CommonJS `require()` statements.
Use CommonJS `require` syntax: `const WebSocket = require('faye-websocket');`. The library does not provide native ESM exports.Ensure your HTTP server is configured to listen for and handle the `upgrade` event (e.g., `http.createServer().on('upgrade', ...)` in Node.js). If using a proxy, verify that it's configured to correctly proxy WebSocket upgrade requests, including the `Connection: Upgrade` and `Upgrade: websocket` headers.The `Client` class is a static property of the main `WebSocket` object. Import the main `WebSocket` object first, then access `WebSocket.Client`: `const WebSocket = require('faye-websocket'); const client = new WebSocket.Client(...);`.