# node-web-gpio

> GPIO access with Node.js

Latest version **2.0.0** (published 2026-09-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-web-gpio
pnpm add node-web-gpio
yarn add node-web-gpio
bun add node-web-gpio
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-09-19 |
| First published | 2019-10-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 22.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 6 |
| Author | Kohei Watanabe |
| Maintainers | kou029w, krunaru, sizuhiko, gurezo, saxallan, satakagi, dynamis, tadfmac |
| Keywords | gpio, hardware, iot, linux, pi, raspberry, raspberry pi, raspi, robot, robotics, robots, rpi |

## Links

- npm: https://www.npmjs.com/package/node-web-gpio
- Repository: https://github.com/chirimen-oh/node-web-gpio
- Homepage: https://github.com/chirimen-oh/node-web-gpio#readme
- Issues: https://github.com/chirimen-oh/node-web-gpio/issues
- npm.io page: https://npm.io/package/node-web-gpio

## Dependencies (1)

- [epoll](https://npm.io/package/epoll.md) ^4.0.2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-09-19
- 2.0.0-beta.0 (beta) — 2026-09-18
- 1.1.81 — 2026-09-14
- 1.1.80 — 2026-09-07
- 1.1.79 — 2026-09-01
- 1.1.78 — 2026-08-25
- 1.1.77 — 2026-08-25
- 1.1.76 — 2026-08-25
- 1.1.75 — 2026-08-25
- 1.1.74 — 2026-08-24
- 1.1.73 — 2026-08-17
- 1.1.72 — 2026-08-03
- 1.1.71 — 2026-07-27
- 1.1.70 — 2026-07-13
- 1.1.69 — 2026-07-06
- … 98 more at https://npm.io/package/node-web-gpio/versions

## README

# node-web-gpio

GPIO access with Node.js

> [!NOTE]
> Linux only. This library uses the sysfs GPIO interface (`/sys/class/gpio`) and the native `epoll` addon for hardware interrupts, neither of which exist on Windows/macOS.

## Usage

```
$ npm i node-web-gpio
```

```js
import { requestGPIOAccess } from "node-web-gpio";
import { setTimeout as sleep } from "node:timers/promises";

const gpioAccess = await requestGPIOAccess();
const port = gpioAccess.ports.get(26);

await port.export("out");

while (true) {
  await port.write(1);
  await sleep(1000);
  await port.write(0);
  await sleep(1000);
}
```

### Input with hardware interrupts (epoll)

Input ports are watched via the Linux epoll API instead of polling, so `onchange` fires immediately on a hardware interrupt without dropping fast pulses.

```js
const port = gpioAccess.ports.get(17);

await port.export("in", { edge: "rising", debounce: 10 });

port.onchange = (event) => {
  console.log(event.value);
};
```

`export()` accepts an optional second argument (only applied when `direction` is `"in"`):

| Option      | Type                              | Default        | Description                                                        |
| ----------- | --------------------------------- | -------------- | ------------------------------------------------------------------ |
| `edge`      | `"rising" \| "falling" \| "both"` | `"both"`       | Which voltage transition fires `onchange`.                         |
| `debounce`  | `number`                          | `0` (disabled) | Milliseconds of chatter (e.g. mechanical switch bounce) to ignore. |
| `activeLow` | `boolean`                         | `false`        | Inverts the logic level (`1` when LOW, `0` when HIGH).             |

Since this relies on the native `epoll` package, a build toolchain (e.g. `build-essential` and `python3` on Debian/Raspberry Pi OS) is required when installing on Linux.

## Document

- [TSDoc](https://npmx.dev/package-docs/node-web-gpio)

## Reference

- [Web GPIO API for W3C Draft](http://browserobo.github.io/WebGPIO)

## Acknowledgments

- [node-web-gpio-onoff](https://github.com/satakagi/node-web-gpio-onoff) by [@satakagi](https://github.com/satakagi). This library's `onchange` handling is based on its epoll-based interrupt-driven approach.

---
_Source: https://npm.io/package/node-web-gpio · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
