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

piapi

v1.0.2

Published

Client library for interfacing with PiAPI running on your raspberry pi

Readme

PiAPI NPM

Bolillo Kremer

Overview

This user friendly library allows you to easily interface with multiple raspberry pi's at once using PiAPI. The simplicity of this library makes it easy for anybody to use. Most functionality is based off of onoff, which is running on PiAPI.

For updates on this project and other other entertainging coding projects, please subscribe to my YouTube channel, Bolillo Kremer.

How to use

Requirements

This library requires that PiAPI is running on your raspberry pi. You can install it on your pi with just one command! To see instructions, click here.

Initializing

You can download the PiAPI's NPM package with the following command...

npm install piapi --save

Next you need to set up a connection to PiAPI like this...

const {Pi} = require("piapi");
//Initialize Pi object with IP address and port of pi
var myPi = new Pi("192.168.1.100", Pi.defaultPort());

//You need to specify which pins will be set as input or output
myPi.initPin(2, "in");
myPi.initPin(3, "out");

//Unexports all pins on the Pi
myPi.cleanExit();

If you would rather provide a specific url than using an IP address and a port, you can do so like this.

var myPi = new Pi("http://192.168.1.100:5000");

Interfacing

You can get the state (0 or 1) of a given pin using this function

//Returns the state of pin 2 as a string
myPi.getState(2);

You can also get a JSON object of all the pin states using this function.

//Returns a Newtonsoft.Json.Linq.JObject
myPi.getStates();

If you want to set the state (0 or 1) of a pin, use this function

//Sets pin 2 to state 0
myPi.setState(2, 0);

Alternatively, you can use "toggle" to toggle the pins state

//Sets pin 2 to state 0
myPi.setState(2, "toggle");

If you wish to set the state of all initiated pins, you can do so with the setAllStates() function.

Customize PiAPI

If you add any GET or POST methods to PiAPI on your Pi, you can access them with the Get and Post functions in PiAPI.Utilities. Additionaliy, you can access the raw url of PiAPI by calling Utilities.RawUrl.

Example
const {Pi, Utilities} = require("piapi");
//Posts "Some Content" to PiAPI
var POSTResponse = await Utilities.post(myPi.rawUrl + "/SomePost", "Some content");

//Gets Response from PiAPI
var GETResponse = await Utilities.get(myPi.rawUrl + "/SomeGet");

API Settings

This library also allwos you to interface with the PiAPI settings.

The settings will take place on server reboot.

Example

//Changes port to 6000
myPi.setAPIPort(6000);

Helpers

Memorizing all the terminology such as "in", "out", "up", "down" can be confusing for some. That's where PiAPI.Helpers come in. These are just simple constant variables that can help you use PiAPI more easily.

Example

const {Pi, Utilities, Helpers} = require("piapi");
var myPi = new Pi("192.168.1.100", Pi.defaultPort());

myPi.initPin(2, Helpers.Pin.in(), Helpers.Edge.rising());
myPi.getState(2);

myPi.cleanExit();

Other Functions

In Utilities there is a function called wait that can be used to wait a given amount of miliseconds before moving on to the next line of execution. It can be implemented like this...

const {Pi, Utilities, Helpers} = require("piapi");
var myPi = new Pi("192.168.1.100", Pi.defaultPort());

myPi.initPin(2, "out");
myPi.setState(2, 1);

//Waits 1 second before moving on
await wait(1000)

myPi.setState(2, 0);

myPi.cleanExit();

For updates on this project and other other entertainging coding projects, please subscribe to my YouTube channel, Bolillo Kremer.