r/javascript • • 25d ago • Obsessed 1 This 1 Bravo 1

serialport-rs for Node.js: Rust-backed serial ports for Node.js with parallel I/O and SerialPort-compatible APIs

https://github.com/DragonWork/node-serialport-rs

I recently ran into an issue with @serialport/bindings-cpp on Node.js 26.4, where serial reads could stall until unrelated JavaScript activity occurred.

While investigating the issue and contributing fixes upstream, I started experimenting with an alternative implementation using Rust and N-API, because upstream seems to be unmaintained for more than a year now.
The result is serialport-rs for Node.js, which uses the existing Rust serialport crate underneath and aims to preserve the familiar Node.js SerialPort API.

The implementation uses dedicated native I/O workers rather than relying on JavaScript-side polling. Initial benchmarks have also shown some promising latency improvements.

It’s available on npm if anyone is interested in trying it:
https://www.npmjs.com/package/serialport-rs

7 Upvotes

3 comments sorted by

1

u/ortegaj50 6d ago

Dedicated I/O workers should help avoid JS-side polling. How do they preserve read ordering and close/error behavior?

1

u/dragon-95 2d ago

We use our own I/O threads, so waiting for serial data doesn’t tie up a thread in libuv’s worker pool or make JS poll. Ports can share a worker. Each port has one reader, so JS gets the bytes in order.

Calling `close()` cancels pending I/O and emits `close` once. If you unplug the device, that `close` event comes with `err.disconnected === true`.

2

u/Unable-Ad-9092 1d ago • Heartwarming

Thanks! Amazing library! Works fine even with termios2 / 3.25 MBps.