A browser-based WebSocket client for NATS messaging system, version 0.3.3. It enables in-browser connectivity to NATS servers via a WebSocket-to-TCP proxy. The library mirrors the node-nats API, supporting publish/subscribe, request/reply, wildcard subscriptions, queue groups, and clustered connections. Unlike server-side NATS clients, it operates entirely in the browser and requires an external WebSocket proxy. The project appears to be in maintenance mode with no recent updates since 2017.
npm install websocket-natsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic publish, subscribe, request/reply, and close with a WebSocket NATS client in a browser-like environment.
Use a WebSocket proxy like ws-tcp-relay with TLS termination, or use wss:// URLs with a proxy that handles SSL.
Set up and run a proxy such as ws-tcp-relay (https://github.com/isobit/ws-tcp-relay) before connecting.
Consider using the official NATS WebSocket client (nats.ws) from the NATS team, which is actively maintained and supports modern JS.
Use the npm package via a bundler to avoid global scope pollution, or rename the global if necessary.
Always use the object returned by connect() for subscriptions and publications, not the module itself.
Always define at least (msg, reply, subject) in your subscription callbacks, even if you don't use them.
Ensure your WebSocket-to-TCP proxy (e.g., ws-tcp-relay) is running and listening on port 4223, and that the NATS server gnatsd is accessible.
Assign the result of connect() to a variable: var nc = require('websocket-nats').connect(...); nc.publish(...);Check that the proxy is configured to accept WebSocket connections on that URL. Usually the path is just '/', but some proxies require a specific path like '/nats'.
Use the CDN script tag to load the library (adds global 'Nats'), or bundle with Webpack/Browserify.
Check that connection succeeded by listening to the 'connect' event or checking nc.connected before accessing nc.currentServer.