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

hid-relay

v1.1.0

Published

Connect to and control USB relays through the HID interface

Readme

hid-relay

A library which can control a USB relay device using the HID interface. It uses the node-hid library to communicate with the relay board so will work in Node.JS or Electron.

Supported Devices

  • DCTTech.com USB Relay Modules (2,4,6, or 8 relays)
    • Vendor ID: 0x16c0
    • Product ID: 0x05df

Installation

Install the library using your package manager of choice:

npm install hid-relay
pnpm add hid-relay
yarn add hid-relay

Check the node-hid documentation for any additional setup you may need to do to use the library on your system. For example on Linux you may need to set udev rules to allow access to devices without root permissions.

You may also need to perform additional setup to make sure this library works in Electron.

Usage

List all relay boards

Return a list of all the currently connected HID USB Relay boards. By default, the state of each relay on the board is also fetched, but this can be turned off by setting the fetchState option to false.

import { listHidRelayBoards } from "node-hid-relay";

// Get the relay boards
const relayBoards = await listHidRelayBoards();

// Log the serial number of each relay board
for (const board of relayBoards) {
  console.log(`Relay board with serial number: ${board.serialNumber}`);
}

Find a relay board by serial number

Find the relay board with the given serial number. This will return the first board which matches or undefined if none are found.

import { findHidRelayBoardBySerialNumber } from "node-hid-relay";

const board = await findHidRelayBoardBySerialNumber("BRD01");
if (board) {
  console.log(`Found board at path: ${board.path}`);
} else {
  console.log(`Not able to find board`);
}

Set the state of a relay

Set the state of a relay on a HID USB Relay board. Note that this function will not check that the relay index is valid as some relays do not report the number of relays available.

import { listHidRelayBoards, setHidRelayState } from "node-hid-relay";

// Get the relay boards
const relayBoards = await listHidRelayBoards();

// Turn the first relay on the first board on
await setHidRelayState(relayBoards[0], 0, true);

// Turn the first relay on the first board off
await setHidRelayState(relayBoards[0], 0, false);

You can also avoid listing by passing in connection details directly:

await setHidRelayState({ serialNumber: "BRD01" }, 0, false);
await setHidRelayState({ path: "DevSrvsID:4405099000" }, 0, false);
await setHidRelayState({ vendorId: 0x16c0, productId: 0x05df }, 0, false);

Set the serial number of a relay board

Set the serial number of a HID USB Relay board. Note that the serial number must contain only ascii characters and must be 5 characters or less.

import { listHidRelayBoards, setHidRelaySerialNumber } from "node-hid-relay";

// Get the relay boards
const relayBoards = await listHidRelayBoards();

// Set the serial number of the first relay board
await setHidRelaySerialNumber(relayBoards[0], "BRD01");

You can also avoid listing by passing in connection details directly:

await setHidRelaySerialNumber({ serialNumber: "BRD01" }, "BRD02");
await setHidRelaySerialNumber({ path: "DevSrvsID:4405099000" }, "BRD02");
await setHidRelaySerialNumber({ vendorId: 0x16c0, productId: 0x05df }, "BRD02");

Development

  • Run pnpm install to install the dependencies.
  • Run pnpm build to build the library.
  • Run pnpm typecheck to run the type checker.
  • Run pnpm lint to run the linter.

See Also

  • usbrelay - This project is inspired by that project
  • node-hid - The Node.JS HID library this project uses

License

MIT