Registry / messaging / sockette

sockette

JSON →
library2.0.6jsnpmunverified

Sockette is a tiny (367 bytes) WebSocket wrapper with automatic reconnection, written by lukeed. Current stable version is 2.0.6. It provides a simple API to manage WebSocket connections, including automatic reconnection with configurable timeout and max attempts. Unlike raw WebSocket or heavier libraries like Socket.IO, Sockette is minimal and does not include fallback transports or extra features. It is ESM-only since v2 and includes TypeScript definitions. The package has low release cadence (last release 2020) and is considered stable and feature-complete.

npm install sockette
INSTALL
IMPORT
SIG · SOCKETTE
S
sockette
messagingjavascriptv2.0.6
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.

Sockette
import Sockette from 'sockette'
const Sockette = require('sockette')
Sockette is an ESM-only package. CommonJS require() will work only if bundler supports it.
Sockette (type)
import type Sockette from 'sockette'
TypeScript users can import the type for type annotations.
SocketteOptions
import { type SocketteOptions } from 'sockette'
import { SocketteOptions } from 'sockette'
Sockette exports SocketteOptions as a type. Use type import to avoid bundling.

Create a Sockette instance with event listeners, send a message and JSON, then close after 5 seconds.

import Sockette from 'sockette'; const ws = new Sockette('wss://echo.websocket.org', { timeout: 5000, maxAttempts: 10, onopen: e => console.log('Connected!', e), onmessage: e => console.log('Received:', e), onreconnect: e => console.log('Reconnecting...', e), onmaximum: e => console.log('Stop Attempting!', e), onclose: e => console.log('Closed!', e), onerror: e => console.log('Error:', e) }); ws.send('Hello, world!'); ws.json({ type: 'ping' }); setTimeout(() => ws.close(), 5000);
Debug
Known issues
breakingDefault import is ESM-only since v2; require() may break in pure Node ESM environments.
fix
Use import syntax or dynamic import if using CommonJS.
affects: >=2.0.0
deprecatedPassing -1 to maxAttempts is deprecated; use Infinity or a large number instead.
fix
Set maxAttempts to a high value like 9999 instead of -1.
affects: >=2.0.0
gotchaSockette does not expose the underlying WebSocket directly; access via event.target in callbacks.
fix
Use event.target inside event handlers to get the raw WebSocket instance.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: sockette_1.default is not a constructor
Using CommonJS require() when package is ESM-only or when bundler misconfigures default export.
fix
Use 'import Sockette from "sockette"' or configure bundler to handle ESM.
Module not found: Can't resolve 'sockette'
Package not installed or missing from node_modules.
fix
Run 'npm install sockette' or 'yarn add sockette'.
Upgrade
Version history
2.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
sockette — npm install sockette · libregistry