Registry / iot / serial-websocket

serial-websocket

JSON →
library1.0.9jsnpmunverified

A bidirectional WebSocket-to-serial port bridge for Node.js, allowing web clients to send/receive commands to Arduino or Raspberry Pi boards via serial. Version 1.0.9 is the latest release. It supports multiple WebSocket connections simultaneously and provides a simple API to configure serial port name and baud rate. Useful for IoT and robotics projects requiring real-time communication between a browser and serial devices.

npm install serial-websocket
INSTALL
IMPORT
SIG · SERIAL-WEBSOCKET
S
serial-websocket
iotjavascriptv1.0.9
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
const serialWebsocket = require('serial-websocket'); const server = serialWebsocket(options);
import serialWebsocket from 'serial-websocket';
This package is CJS-only; ESM import will fail due to missing default export.
start()
server.start();
serialWebsocket.start(options);
start() is a method on the returned instance, not on the imported function.
stop()
server.stop();
serialWebsocket.stop();
Ensure server instance is assigned before calling stop().

Creates a bidirectional WebSocket-to-serial bridge on port 8081 connected to the specified serial port.

const options = { serialPortName: '/dev/cu.usbmodem142301', serialPortNameRate: 9600, webSocketPortNumber: 8081 }; const serialWebsocket = require('serial-websocket'); const server = serialWebsocket(options); server.start(); console.log('WebSocket server running on port 8081');
Debug
Known issues
breakingThe package is CommonJS-only; ESM import (import serialWebsocket from 'serial-websocket') results in TypeError: serial_websocket is not a function
fix
Use require('serial-websocket') instead of import.
affects: >=1.0.0
gotchaOptions object property serialPortNameRate is misspelled (should be baudRate commonly), but it works as intended.
fix
Be careful with the name; it is a string, not a number.
affects: >=1.0.0
gotchaThe package does not expose stop() in some early versions, causing resource leak.
fix
Upgrade to version >=1.0.6 to have stop() available.
affects: <1.0.6
deprecatedUsing default export via require() returns an object, not a class. Calling new serialWebsocket() will fail.
fix
Invoke serialWebsocket(options) as a function (not constructor).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: serial_websocket is not a function
Using ESM import or calling new on the default export.
fix
Use const serialWebsocket = require('serial-websocket'); const server = serialWebsocket(options);
Error: Cannot find module 'serialport'
Missing peer dependency serialport.
fix
Run npm install serialport in your project.
TypeError: server.start is not a function
Calling start() directly on the imported function instead of on the returned instance.
fix
Assign the result of serialWebsocket(options) to a variable, then call start() on that variable.
Error: listen EADDRINUSE :::8081
WebSocket port 8081 is already in use.
fix
Change webSocketPortNumber option to an unused port.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies
serialportrequiredSerial port communication library
wsrequiredWebSocket server implementation
log-with-statusbarrequiredLogging utility used by the package
Agent activity
20 hits · last 30 days
node
16
Amazon
1
Resources