npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tiny-serial

v2.0.0

Published

A small serialport library with native Rust bindings

Readme

header image

tiny-serial

tiny-serial is a serial port library for Node.js that also works in Bun. It uses a thin native layer written in Rust for OS syscalls. All streams, parsers, and the mock API are written in TypeScript.

npm version

Motivation

This library is strongly inspired by serialport/node-serialport. However, it is currently not supported in Bun as documented in various Github issues. The reasons seem to lie in how NodeJS handles native modules (libuv) as opposed to Bun.

tiny-serial uses a thin layer written in Rust to circumvent this.

The library is small and doesn't cover the full functionality of serialport, but comes with all the basic functions you would expect.

Install

npm install tiny-serial
yarn install tiny-serial
pnpm install tiny-serial
bun add tiny-serial

Usage

import { SerialPort, ReadlineParser } from 'tiny-serial'

const port = new SerialPort({ path: '/dev/ttyUSB0', baudRate: 9600 })
const parser = port.pipe(new ReadlineParser({ delimiter: '\n' }))

parser.on('data', (line) => console.log(line))

await port.write(Buffer.from('hello\n'))
await port.close()

API

new SerialPort(options)

export interface SerialPortOptions {
  path: string
  baudRate: number
  dataBits?: 5 | 6 | 7 | 8
  stopBits?: 1 | 1.5 | 2
  parity?: 'none' | 'odd' | 'even' | 'mark' | 'space'
  rtscts?: boolean
  xon?: boolean
  xoff?: boolean
  autoOpen?: boolean
}

Methods: open(), close(), write(data), setPin(pin, value), listPorts()

Parsers

  • ReadlineParser: Split on a delimiter string (default \n)
  • ByteLengthParser: Emit fixed-size chunks
  • RegexParser: Split on a regex match
  • InterByteTimeoutParser: Emit after a silence gap (ms)

MockSerialPort

Drop-in replacement with no native dependencies — use in tests and CI.

import { MockSerialPort } from 'tiny-serial'

const mock = new MockSerialPort({ path: '/dev/mock', baudRate: 9600 })
mock.simulateData(Buffer.from('hello\n'))

Development

bun run build:debug   # Rust (debug) + TypeScript
bun run test          # AVA tests (Node)
bun run test:bun      # bun test
bun run bench         # parser benchmarks

Hardware tests require socat: ./scripts/test-hardware.sh

Performance

Parser benchmarks vs. the serialport package:

| | Task name | Latency avg (ns) | Latency med (ns) | Throughput avg (ops/s) | Throughput med (ops/s) | Samples | | --- | ------------------------------------------------------ | ---------------- | ---------------- | ---------------------- | ---------------------- | ------- | | 0 | tiny-serial ReadlineParser — 100 lines × 64 B | 51297 ± 2.48% | 47084 ± 1251.0 | 20640 ± 0.13% | 21239 ± 579 | 19495 | | 1 | serialport ReadlineParser — 100 lines × 64 B | 106603 ± 3.73% | 98959 ± 5041.0 | 9921 ± 0.22% | 10105 ± 519 | 9381 | | 2 | tiny-serial ByteLengthParser — 1000 B / 8-byte packets | 9253.0 ± 5.55% | 8083.0 ± 500.00 | 119869 ± 0.08% | 123716 ± 8140 | 108074 | | 3 | serialport ByteLengthParser — 1000 B / 8-byte packets | 9155.4 ± 1.62% | 8458.0 ± 500.00 | 114533 ± 0.08% | 118231 ± 6769 | 109226 | | 4 | tiny-serial RegexParser — 100 lines × 64 B | 22288 ± 1.02% | 20875 ± 1292.0 | 46899 ± 0.11% | 47904 ± 3051 | 44868 | | 5 | serialport RegexParser — 100 lines × 64 B | 28545 ± 0.72% | 26875 ± 791.00 | 36010 ± 0.10% | 37209 ± 1119 | 35033 |

License

MIT