Registry / messaging / websocket-lowfat-promise

websocket-lowfat-promise

JSON →
library1.1.12jsnpmunverified

A zero-dependency promise wrapper for ws-compatible WebSocket objects. Version 1.1.12 provides a minimal, low-fat API that promisifies open, send, recv, ping, and close operations. Works in browser and Node.js environments that support promises. Unlike heavier alternatives like 'ws-wrapper' or 'reconnecting-websocket', this package is deliberately minimal (≈30 lines) with no dependencies, making it ideal for lightweight or embedded use cases. Its release cadence is low; last update was in 2021.

npm install websocket-lowfat-promise
INSTALL
IMPORT
SIG · WEBSOCKET-LOWFAT-P
W
websocket-lowfat-promise
messagingjavascriptv1.1.12
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import wspromise from 'websocket-lowfat-promise'
const { wspromise } = require('websocket-lowfat-promise')
Package exports a default function/class. Named import will fail in ESM.
default (CJS)
const wspromise = require('websocket-lowfat-promise')
const { default: wspromise } = require('websocket-lowfat-promise')
In CommonJS, require returns the full module.exports object directly.
TypeScript type
import type WSPromise from 'websocket-lowfat-promise'
import WSPromise from 'websocket-lowfat-promise'
If using TS and only need types for the class, use type import to avoid runtime overhead.

Shows how to create a promisified WebSocket, open, send, receive, and close.

const WebSocket = require('ws'); const wspromise = require('websocket-lowfat-promise'); async function runme() { const wsp = new wspromise(new WebSocket('wss://echo.websocket.org')); await wsp.open(); await wsp.send('Hello!'); const response = await wsp.recv(); console.log(response); await wsp.close(); console.log('Done'); } runme().catch(console.error);
Debug
Known issues
gotchawspromise.recv() will never resolve if no message arrives before the connection closes — it does not reject on close.
fix
Wrap recv() with a timeout or listen for 'close' event externally.
affects: >=1.0.0
gotchaThe passed WebSocket must be in 'open' state (or will be opened) — wspromise does not handle auto-reconnection or initial connection backoff.
fix
Ensure the underlying WebSocket is configured correctly before passing to wspromise.
affects: >=1.0.0
gotchaConstructor expects an existing WebSocket instance; it does not accept a URL string.
fix
First create a WebSocket instance, then pass it to new wspromise(ws).
affects: >=1.0.0
deprecatedThis package has not been updated since 2021. It may not support recent Node.js versions or security patches.
fix
Consider alternatives like 'ws' with manual Promise wrapping or 'async-ws' for actively maintained solutions.
affects: all
Errors
Common errors & fixes
Error: WebSocket is not open: readyState 0 (CONNECTING)
Calling send() or recv() before awaiting open().
fix
Always await wsp.open() before any other operations.
TypeError: wspromise is not a constructor
Using default import in CommonJS vs ESM incorrectly.
fix
Use const wspromise = require('websocket-lowfat-promise'); (CJS) or import wspromise from 'websocket-lowfat-promise'; (ESM).
TypeError: (intermediate value).recv is not a function
Passing an invalid WebSocket object (e.g., no 'on' or 'removeListener').
fix
Ensure the argument is a ws-compatible WebSocket instance with standard event methods.
UnhandledPromiseRejectionWarning: Error: WebSocket is not open
Attempting to send/recv before open completes or after close, and not catching the rejection.
fix
Wrap calls in try/catch or use .catch() to handle promise rejections properly.
Upgrade
Version history
1.1.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
22
OpenAI (training)
1
Resources
websocket-lowfat-promise — npm install websocket-lowfat-promise · libregistry