Registry / messaging / bare-ws

bare-ws

JSON →
library3.0.0jsnpmunverified

A lightweight WebSocket library for JavaScript environments, targeting Bare and Node.js. Version 3.0.0 provides both client and server WebSocket functionality with a simple stream-like API. It is actively maintained by Holepunch and offers TypeScript support. Compared to alternatives like ws, bare-ws is optimized for Bare runtime and has minimal dependencies.

npm install bare-ws
INSTALL
IMPORT
SIG · BARE-WS
B
bare-ws
messagingjavascriptv3.0.0
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.

ws
import ws from 'bare-ws'
const ws = require('bare-ws')
ESM default import is preferred, but CJS require also works.
Server
import { Server } from 'bare-ws'
const { Server } = require('bare-ws')
Named import works in both ESM and CJS.
Socket
import { Socket } from 'bare-ws'
const Socket = require('bare-ws').Socket
Named export exists; avoid destructuring from default export.

Creates a WebSocket server and client, sending and receiving messages.

import ws from 'bare-ws'; const server = new ws.Server({ port: 8080 }, (socket) => { socket.on('data', (data) => { console.log(data.toString()); }); }); server.on('listening', () => { const socket = new ws.Socket({ port: 8080 }); socket.write('Hello WebSocket'); });
Debug
Known issues
breakingSocket constructor options differ from ws library.
fix
Use { port, host, path } instead of URL string.
affects: >=3.0.0
gotchadata event returns Buffer, not string.
fix
Use .toString() to convert Buffer to string.
affects: >=3.0.0
deprecatedThe 'close' event is deprecated, use 'end' instead.
fix
Subscribe to 'end' event for connection close.
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find module 'bare-ws'
Package not installed in node_modules
fix
npm install bare-ws
TypeError: ws.Server is not a constructor
Default import used incorrectly (e.g., import { Server } instead of import ws)
fix
Use import ws from 'bare-ws' then new ws.Server()
Missing binding 'bare-url'
Peer dependency bare-url not installed
fix
npm install bare-url
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
bare-bufferrequiredrequired for buffer operations
bare-urlrequiredrequired for URL parsing
Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
bare-ws — npm install bare-ws · libregistry