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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rpi-relay-hat-api

v1.0.13

Published

An API to control the Waveshare RPi Relay Board

Readme

rpi-relay-hat-api

An API to control the Waveshare RPi Relay Board.

Install dependencies (on Raspberry Pi only)

Install pigpio

sudo apt-get update
sudo apt-get install pigpio

Symlink node, npm & yarn

https://github.com/fivdi/pigpio/issues/124

sudo ln -s "$(which node)" /usr/local/bin/node
sudo ln -s "$(which npm)" /usr/local/bin/npm
sudo ln -s "$(which yarn)" /usr/local/bin/yarn

Install and run the package

yarn dlx rpi-relay-hat-api

Configure the application

Create a rpi-relay-hat-api.env file (in a globally accessible location will allow it to be run as a service, e.g. within /usr/lib/node_modules/rpi-relay-hat-api/) and add details of the channels and server port, something like:

RELAY_HAT_CHANNELS=[{ "channelId": "CH1", "pinNo": 26, "mode": 1, "name": "Mirror Light" }, { "channelId": "CH2", "pinNo": 20, "mode": 1, "name": "Mirror Demister" }]
PORT=3000

| Property | Type | Meaning | Example | |----------|------|---------|---------| | channelId | string | Unique identifier in the format CH{n}, where n is a number between 1 and 9 | CH1 | | pinNo | number | BCM pin number, as per RPi Relay Board - Interface description | 20, 21, or 26 | | mode | number | Default value, 0 for off and 1 for on | 0 or 1 | | name | string | The display name for the switch | Mirror Light |

Run the package

ENV_FILE_PATH=/usr/lib/node_modules/rpi-relay-hat-api/rpi-relay-hat-api.env rpi-relay-hat-api

Development options

Rather than installing the package, these development options allow it to be run and tested:

Download the package

git clone [email protected]:jondarrer/rpi-relay-hat-api
cd rpi-relay-hat-api

Build application

yarn
yarn build

Configure the application for development

Create a .env file and add details of the channels and server port, something like:

RELAY_HAT_CHANNELS=[{ "channelId": "CH1", "pinNo": 26, "mode": 1, "name": "Mirror Light" }, { "channelId": "CH2", "pinNo": 20, "mode": 1, "name": "Mirror Demister" }]
PORT=3000

Run

sudo yarn start

Test

yarn test

Publish

npm version patch -m "%s"
git push && git push --tags

And then create a release based on the tag in GitHub; this will then run the GitHub action to publish the package on npmjs.com.

Endpoints

GET /

Get details of all available relays.

GET /sys-info

Get info about current system.

GET /:id

Get details of a particular relay.

POST /:id/on

Turn a relay on (digital write 1).

POST /:id/off

Turn a relay off (digital write 0).

POST /:id/toggle

Toggles a relay on and off (digital write 1 or 0), inverting its previous state.

Managed process

Use pm2 to setup the script when booting up.

Install pm2

npm i -g pm2
sudo ln -s "$(which pm2)" /usr/local/bin/pm2

Add process to startup script

sudo pm2 start "ENV_FILE_PATH=/home/jondarrer/code/rpi-relay-hat-api/.env sudo yarn --cwd /home/jondarrer/code/rpi-relay-hat-api start" --name "waveshare-api"
sudo pm2 startup
sudo pm2 save
# sudo pm2 stop waveshare-api
# sudo pm2 restart waveshare-api
# sudo pm2 delete waveshare-api