{"id":49112,"library":"reconnect-ws","title":"reconnect-ws","description":"A lightweight Node.js module that provides automatic reconnection for websocket-streams when the connection drops. Based on reconnect-core, it wraps websocket-stream to create a persistent stream that reconnects on failure. Version 0.1.0 is the latest release; the package has seen no updates since 2013 and should be considered in maintenance mode. It is a thin wrapper around websocket-stream and depends on both ws and websocket-stream. Compared to alternatives like reconnecting-websocket, it uses the stream API which may be preferable in streaming contexts but is less flexible for non-stream usage.","status":"maintenance","version":"0.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/jacobbubu/reconnect-ws","tags":["javascript","reconnect","websocket","ws","stream"],"install":[{"cmd":"npm install reconnect-ws","lang":"bash","label":"npm"},{"cmd":"yarn add reconnect-ws","lang":"bash","label":"yarn"},{"cmd":"pnpm add reconnect-ws","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the underlying WebSocket stream that the reconnection logic wraps.","package":"websocket-stream","optional":false},{"reason":"Core WebSocket library used by websocket-stream.","package":"ws","optional":false},{"reason":"Provides the base reconnection logic and event interface.","package":"reconnect-core","optional":false}],"imports":[{"note":"This package uses CommonJS and does not support ESM imports. Use require().","wrong":"import reconnect from 'reconnect-ws';","symbol":"default export","correct":"var reconnect = require('reconnect-ws');"},{"note":"The default export is a factory function, not a constructor. Do not use new.","wrong":"var instance = new require('reconnect-ws')(function(stream) { ... });","symbol":"Reconnect instance","correct":"var instance = require('reconnect-ws')(function(stream) { ... });"},{"note":"Events must be registered before calling .connect() to avoid missing early events.","wrong":"reconnect(function(stream) { ... }).on('reconnect', function(n) { ... }).connect(8080);","symbol":"Reconnect events","correct":"reconnect(function(stream) { ... }).on('reconnect', function(n) { ... });"}],"quickstart":{"code":"var WebSocketServer = require('ws').Server;\nvar wss = new WebSocketServer({ port: 8080 });\nwss.on('connection', function(ws) {\n  ws.send('Hello');\n});\n\nvar reconnect = require('reconnect-ws');\nvar r = reconnect(function(stream) {\n  stream.on('data', function(data) {\n    console.log('Received:', data.toString());\n  });\n});\nr.connect(8080);","lang":"javascript","description":"Creates a WebSocket server and a client that automatically reconnects using reconnect-ws."},"warnings":[{"fix":"Use reconnect({ host: 'example.com', port: 8080 }) for remote hosts.","message":"The .connect() method accepts either a port number (for localhost) or an options object with host/port. Passing only a port number will connect to ws://localhost:<port>.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use .on('connect', function(stream) { ... }) to ensure connection is established.","message":"The stream callback receives a duplex stream, but the stream is not open immediately. Listen for 'connect' event or wait for stream 'open' before sending data.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Ensure your environment uses Node.js with 'ws' installed.","message":"This package depends on websocket-stream, which itself depends on ws. If you use a different WebSocket library (e.g., 'uws' or browser WebSocket), this package will not work.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Consider migrating to a maintained alternative like 'reconnecting-websocket' or implement a custom reconnection layer.","message":"The package is no longer maintained. It uses old versions of dependencies which may have known vulnerabilities.","severity":"deprecated","affected_versions":">=0.0.1"}],"env_vars":null,"search_vec":"'0.1.0':40 '2013':52 'altern':80 'api':89 'around':65 'automat':10 'base':20 'compar':78 'connect':18 'consid':56 'context':96 'core':24 'creat':31 'depend':70 'drop':19 'failur':38 'flexibl':100 'javascript':106 'latest':43 'less':99 'lightweight':5 'like':81 'mainten':58 'may':91 'mode':59 'modul':7 'node.js':6 'non':103 'non-stream':102 'packag':46 'persist':33 'prefer':93 'provid':9 'reconnect':2,11,23,36,83,107 'reconnect-cor':22 'reconnect-w':1 'reconnecting-websocket':82 'releas':44 'seen':48 'sinc':51 'stream':15,29,34,68,77,88,95,104,110 'thin':63 'updat':50 'usag':105 'use':86 'version':39 'websocket':14,28,67,76,84,108 'websocket-stream':13,27,66,75 'wrap':26 'wrapper':64 'ws':3,73,109","created_at":"2026-06-07T17:00:07.031153+00:00","updated_at":"2026-06-07T17:00:07.031153+00:00","problems":[{"fix":"npm install websocket-stream ws","cause":"websocket-stream is a required peer dependency not bundled with reconnect-ws.","error":"Cannot find module 'websocket-stream'"},{"fix":"Use const reconnect = require('reconnect-ws');","cause":"Using ES6 import syntax (import reconnect from 'reconnect-ws') which is not supported.","error":"reconnect is not a function"},{"fix":"reconnect(function(stream) { ... }); always provide a callback.","cause":"Calling reconnect() without a callback function argument.","error":"TypeError: listener must be a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/jacobbubu/reconnect-ws","github":"git://github.com/jacobbubu/reconnect-ws","docs":null,"changelog":null,"pypi":null,"npm":"reconnect-ws","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}