Registry / http-networking / webstomp-client

webstomp-client

JSON →
library1.2.6jsnpmunverified

webstomp-client is a JavaScript library providing a STOMP client over WebSockets for both browser and Node.js environments. Currently at version 1.2.6, it does not follow a fixed release cadence but rather ships updates as needed, addressing bug fixes and minor enhancements. This project is an active fork of the original `stomp-websocket` library by Jeff Mesnil and Jeff Lindsay, having been rewritten in ES6 to modernize its codebase and integrate community-contributed pull requests that were pending in the upstream project. Its key differentiators include modern ES6 syntax, built-in TypeScript type definitions, and explicit support for supplying custom WebSocket implementations (e.g., `ws` or `sockjs-client` in Node.js) via the `webstomp.over()` method, rather than relying solely on a global `WebSocket` object like its predecessor or browser-only alternatives. For browser environments, it automatically uses the global `WebSocket` object. It provides a robust API for connecting, subscribing, sending messages, and handling disconnections with STOMP servers like RabbitMQ Web-STOMP.

npm install webstomp-client
INSTALL
IMPORT
SIG · WEBSTOMP-CLIENT
W
webstomp-client
http-networkingjavascriptv1.2.6
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

webstomp
✓ import webstomp from 'webstomp-client';
✗ import { webstomp } from 'webstomp-client';
Since v1.2.3, the package exclusively uses a default export. Named imports for the main 'webstomp' object will fail.
Client (type)
✓ import type { Client } from 'webstomp-client';
Type import for the STOMP Client instance.
Frame (type)
✓ import type { Frame } from 'webstomp-client';
Type import for STOMP frame objects returned in callbacks.
webstomp (CommonJS)
✓ const webstomp = require('webstomp-client');
Standard CommonJS import pattern. The `webstomp` object will contain `client`, `over`, etc.

Demonstrates connecting to a STOMP server via WebSockets in a Node.js environment using `webstomp.over()`, subscribing to a queue, sending a message, and properly disconnecting. Requires a running STOMP server (e.g., RabbitMQ with Web-STOMP plugin) and the `ws` npm package for Node.js WebSocket support.

import webstomp from 'webstomp-client'; import WebSocket from 'ws'; // For Node.js, install 'ws': npm install ws const WEBSOCKET_URL = process.env.STOMP_WS_URL ?? 'ws://localhost:15674/ws'; // Example: RabbitMQ Web-STOMP const STOMP_USER = process.env.STOMP_USER ?? 'guest'; const STOMP_PASS = process.env.STOMP_PASS ?? 'guest'; async function runStompClient() { console.log(`Attempting to connect to STOMP WebSocket at: ${WEBSOCKET_URL}`); // In Node.js, a WebSocket implementation must be explicitly provided to webstomp.over() // The protocols array ensures the WebSocket connection is established with STOMP-compatible subprotocols. const ws = new WebSocket(WEBSOCKET_URL, ['v10.stomp', 'v11.stomp', 'v12.stomp']); const client = webstomp.over(ws, { debug: true, heartbeat: { incoming: 10000, outgoing: 10000 } // Configure heartbeats }); client.connect( { login: STOMP_USER, passcode: STOMP_PASS }, (frame: webstomp.Frame) => { console.log('Successfully connected to STOMP server:', frame.headers['session']); client.subscribe('/queue/example', (message: webstomp.Frame) => { console.log('Received message:', message.body); }, { id: 'my-subscription' }); // Include a unique ID for the subscription console.log('Subscribed to /queue/example'); setTimeout(() => { const messageBody = `Hello from webstomp-client at ${new Date().toISOString()}`; client.send('/queue/example', messageBody, { 'content-type': 'text/plain' }); console.log('Sent message:', messageBody); }, 2000); setTimeout(() => { client.disconnect(() => { console.log('Disconnected from STOMP server.'); ws.close(); }); }, 5000); }, (error: webstomp.Frame | CloseEvent) => { console.error('STOMP connection error:', error); if (error instanceof CloseEvent) { console.error(`WebSocket closed with code ${error.code} and reason: ${error.reason}`); } ws.close(); } ); ws.onopen = () => console.log('WebSocket connection opened.'); ws.onclose = () => console.log('WebSocket connection closed.'); ws.onerror = (err: Event) => console.error('WebSocket error:', err); } runStompClient().catch(console.error);
Debug
Known issues
breakingVersion 1.2.3 removed mixed (named and default) exports. The library now exclusively uses a default export. If you were using named imports like `import { client, over } from 'webstomp-client';`, these will break.
fix
Change your imports to `import webstomp from 'webstomp-client';` and access methods as `webstomp.client()` or `webstomp.over()`.
affects: >=1.2.3
gotchaIn Node.js environments, `webstomp-client` does not provide a default WebSocket implementation. You must explicitly provide a WebSocket-alike object instance (e.g., from the `ws` or `sockjs-client` packages) to the `webstomp.over()` method.
fix
Install a WebSocket client (`npm install ws`) and use `webstomp.over(new WebSocket(url))` instead of `webstomp.client(url)`.
affects: >=1.0.0
gotchaThe `connect` method has multiple overloads for parameters (headers vs. login/passcode). Ensure you pass parameters correctly to avoid connection issues.
fix
Refer to the API documentation for the correct `connect` signature matching your authentication method. Example: `client.connect({ login, passcode }, connectCallback)` or `client.connect(headers, connectCallback)`.
affects: >=1.0.0
gotchaWhen connecting to SockJS-based STOMP servers, it's often recommended to disable heartbeats by setting `heartbeat: false` in the options object passed to `client()` or `over()`.
fix
Pass `{ heartbeat: false }` in the options object during client initialization: `webstomp.over(ws, { heartbeat: false })`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: webstomp.client is not a function
Attempting to use `webstomp.client()` in Node.js where `WebSocket` is not globally available, or trying to use `client` as a named import after v1.2.3.
fix
For Node.js, use `webstomp.over(new WebSocket(url))` with a custom WebSocket implementation like `ws`. Ensure you are using the default import: `import webstomp from 'webstomp-client';`.
ReferenceError: WebSocket is not defined
Using `webstomp.client(url)` in a Node.js environment without globally polyfilling the `WebSocket` object.
fix
In Node.js, explicitly use `webstomp.over(ws_instance)` and pass an instance of a Node.js WebSocket client (e.g., from the `ws` package). Alternatively, you could polyfill `global.WebSocket = require('ws');` but `webstomp.over` is the idiomatic way.
TS2305: Module '"webstomp-client"' has no exported member 'Client'.
Trying to import the `Client` type (or `Frame` type) as a value import.
fix
Use a type-only import: `import type { Client } from 'webstomp-client';`.
Upgrade
Version history
1.2.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
23
OpenAI (training)
1
Resources
webstomp-client — npm install webstomp-client · libregistry