ws-reconnect is a lightweight Node.js WebSocket client with automatic reconnection logic. Version 1.0.7 is the current stable release, but the package has not been updated since 2019. It provides event-driven reconnection with configurable retry count and reconnect interval. Unlike more modern alternatives (e.g., reconnecting-websocket), this package is minimal, untyped, and does not support browser environments or the standard WebSocket API. It depends on the 'ws' library. Note: The constructor is named WSCLIENT (not WSCLINET as in the README example).
npm install ws-reconnectNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a WebSocket server and connect using ws-reconnect with reconnection options and event listeners.
Use new WSCLIENT(url, opts) — note all caps, no typo.
Set retryCount to the desired number of reconnection attempts (initial connection not counted).
Use require('ws-reconnect') or configure TypeScript with 'esModuleInterop' and 'import = require'.Create a custom type declaration or use '@ts-ignore'.
Run 'npm install ws' alongside ws-reconnect.
Use 'const WSCLIENT = require("ws-reconnect")' in Node.js CJS.Attach a 'error' event listener on the client object: client.on('error', (err) => console.error(err));