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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@9wick/node-web-serial-ponyfill

v0.5.3-beta.4

Published

An implementation of the Serial API on top of the Node.js serialport package.

Downloads

83

Readme

codecov GitHub npm node-current (tag)

An implementation of the Serial API on top of the Node.js serialport package.

What is this?

For example, you wrote a program that connect to a device through Web Serial API.

(async function () {
    let filters = [{ usbVendorId: 10376 }];

    let port = await navigator.serial.requestPort({ filters });

    await port.open({ baudRate: 115200 });

    let reader = port.readable.getReader();
    let writer = port.writable.getWriter();

    await writer.write(Uint8Array.from([201, 54, 184, 71, 86, 34, 0, 96, 252]));

    ...

    await reader.cancel();
    await writer.close();
    await port.close();
})();

It works on the browser. Now, you want to do the same things in the Node.js environment. However, Web Serial API is not supported in Node.js. You need to install a package called serialport and you won't be able to reuse the code since the API is different.

With this library, you can write a program that works on both browser and Node.js environment. All you need to do is import this package and change a few lines of code:

+ import { serial } from "node-web-serial-ponyfill";

(async function () {
    let filters = [{ usbVendorId: 10376 }];

-   let port = await navigator.serial.requestPort({ filters });
+   let port = await serial.requestPort({ filters });

    await port.open({ baudRate: 115200 });

    ...
})();

By doing this, you can now connect to a device in a Node.js program without changing the code.

But wait, what about the user interface?

Good question! The user interface is the same as the browser. If you ask the user to select a serial port, they will be able to select one from the console.

Ask user to select a port in the console

More features:

In addition, you can still do everything you can do in Node.js. For example, you can connect to a serial port by providing the path name. So we provide you the findPort method which will return the port that matches the given path name. It's specific to Node.js and you can't do it in the browser. Here is the type definition of this package.

interface NodeSerial extends Serial {
    /**
     * Returns all serial ports connected to the host filtered by the options.
     */
    listPorts(options?: SerialPortRequestOptions): Promise<SerialPort[]>;
    
    /**
     * Returns a SerialPort on the path.
     */
    findPort(portPath: string): Promise<SerialPort | undefined>;
    
    ...
}

...

declare const serial: NodeSerial;

Differences:

  • Events connect and disconnect are not implemented.
  • Events open and close are implemented in the serial port class.
  • A serial port can be closed without releasing the readable and writable streams.

Development

Remember to install the following package:

npm install -g win-node-env

Good Luck!