A lightweight, TypeScript-ready WebSocket module providing essential lifecycle event handlers (onOpen, onResponse, onError, onClose) and core functions (initWebSocket, send, closeWS). Version 1.0.12 offers minimal abstraction over the native WebSocket API, with no external dependencies. Suitable for projects needing a simple wrapper with TypeScript support. Release cadence is low; primarily maintenance.
npm install base-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initializes a WebSocket connection to an echo server, sends a message, logs responses, and closes after 5 seconds.
Use the provided send() and closeWS() functions instead of manipulating the WebSocket directly.
Implement custom reconnection logic in the onClose or onError callbacks.
Assume data is already parsed; handle errors if server sends invalid JSON.
N/A
Call send() only inside onOpen callback to ensure the connection is established.
Use import { closeWS } from 'base-websocket'.Install and import a WebSocket polyfill like 'ws' before using base-websocket in Node.js.