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

gpio-promise

v1.1.2

Published

Talk to your Raspberry PI's general purpose inputs and outputs with promises

Readme

gpio-promise

A fork of https://github.com/EnotionZ/GpiO to use es6 promises instead of callbacks. I have also changed the API slightly.

The code is written in es6 but compiled with 6to5 to es5 to be used with node as `require('gpio-promise').

Installation

Get node.js on your Raspberry Pi

On Raspbian, you can simply run apt-get install nodejs, otherwise, compile it

Usage

This library is an npm package, just define gpio-promise in your package.json dependencies or

npm install gpio-promise

Note: you must be running as root or have the proper priviledges to access the gpio headers

Standard setup

var GpioPin = require("gpio-promise");

var gpio4 = new GpioPin(4);

gpio4
   .open('out')
   .then(function() {
      // All methods returns Promise
      return gpio4.high();
   });

The constructor also takes an optional object containing options

var gpio4 = new GpioPin(4, {interval: 200});

Header direction "in"

If you plan to set the header voltage externally, use direction in and read value from your program.

var GpioPin = require("gpio-promise");
var gpio4 = new GpioPin(4);

gpio4
   .open('in')
   .then(function() {
      // Its ready now
   });

API Methods

All API Methods below return Promise.

var GpioPin = require("gpio-promise");
var gpio4 = new GpioPin(4);

/** Open pin */
gpio4.open('in');
gpio4.open('out');

// Or use the convenient methods
gpio4.in();
gpio4.out();

/** Set value */
gpio4.set(0);
gpio4.set(1);
gpio4.set('low');
gpio4.set('high');

/** Toggle value between 1 and 0 */
gpio4.toggle();

/*
 * Unexport program when done
 */
process.on('SIGINT', function() {
   GpioPin.unexport(4);
});

EventEmitter

This library uses node's EventEmitter which allows you to watch for value changes and fire a callback.

var GpioPin = require("gpio-promise");
var gpio4 = new GpioPin(4);

/** On every change */
gpio4.on('change', function(value) {
   
});

/** Changing from 0 to 1 */
gpio4.on('rising-edge', function(value) {
   
});

/** Changing from 1 to 0 */
gpio4.on('falling-edge', function(value) {
      
});
            
// unbind a particular callback from the "change" event
gpio4.removeListener("change", processPin4);
      
// unbind all callbacks from the "change" event
gpio4.removeAllListeners("change");

Tests

Run the tests with npm test, these use a mock gpio and are only testing this librarys interface.