# detect-rpi

> Detects if node is currently running on a Raspberry Pi.

Latest version **1.6.0** (published 2026-05-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install detect-rpi
pnpm add detect-rpi
yarn add detect-rpi
bun add detect-rpi
```

## Health

**Score 53/100 (C)** — status: active.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2026-05-29 |
| First published | 2017-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/detect-rpi) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | Chris Grieger |
| Maintainers | fourcube |
| Keywords | raspberry, detect pi |

## Links

- npm: https://www.npmjs.com/package/detect-rpi
- Repository: https://github.com/fourcube/detect-rpi
- Homepage: https://github.com/fourcube/detect-rpi#readme
- Issues: https://github.com/fourcube/detect-rpi/issues
- npm.io page: https://npm.io/package/detect-rpi

## Recent versions

- 1.6.0 (latest) — 2026-05-29
- 1.5.0 — 2024-03-19
- 1.4.0 — 2020-01-20
- 1.3.0 — 2018-05-24
- 1.2.0 — 2017-07-23
- 1.1.0 — 2017-05-11
- 1.0.2 — 2017-05-11
- 1.0.1 — 2017-05-11
- 1.0.0 — 2017-05-11

## README

[![npm version](https://badge.fury.io/js/detect-rpi.svg)](https://badge.fury.io/js/detect-rpi)

# detect-rpi

Detect if Node.js is currently running on a Raspberry Pi (including Compute Modules and Pi Zero 2 W).

---

## Install

```bash
npm install detect-rpi --save
```

---

## Usage

```javascript
const isPi = require('detect-rpi');

if (isPi()) {
  console.log('Running on a Raspberry Pi!');
} else {
  console.log('Not running on a Pi.');
}
```

---

## API

The default export is a function that returns a boolean (`true` if running on a Pi, `false` otherwise).  
You can also access several helper functions:

### `isPi()`
Returns `true` if the system is a known Raspberry Pi.

### `isPi.model()`
Returns the string from the `Model` line of `/proc/cpuinfo`, or `null` if not found.

Example:
```text
"Raspberry Pi 4 Model B Rev 1.1"
```

### `isPi.revision()`
Returns the board revision code, or `null` if not available.

Example:
```text
"c03111"
```

### `isPi.info()`
Returns a structured object with all detection info:

```javascript
{
  isPi: true,
  model: "Raspberry Pi Zero 2 W Rev 1.0",
  hardware: "RP3A0",
  revision: "902120"
}
```

---

## Example

```javascript
const isPi = require('detect-rpi');

const info = isPi.info();

if (info.isPi) {
  console.log("Running on a Pi!");
  console.log("Model:   ", info.model);
  console.log("Hardware:", info.hardware);
  console.log("Revision:", info.revision);
} else {
  console.log("Not a Pi.");
}
```

---

## How it works

This module reads `/proc/cpuinfo` and:

- Checks the `Hardware`, `Model`, and `Revision` fields.
- Matches against known Raspberry Pi SoCs, including:
  - `BCM2708`, `BCM2835`, `BCM2711`, `BCM2712`, `RP3A0`, etc.
- Recognizes text like `"Raspberry Pi"` or `"Compute Module"` in the model string.

This works even on **64-bit Raspberry Pi OS Bookworm**, where the `Hardware` field is no longer present.

---

## Supported Models

Includes detection support for:

- Raspberry Pi 1–5
- Raspberry Pi Zero / Zero 2 W
- Compute Module 1–4
- RP3A0 (used in Pi Zero 2 W)
- BCM2712 (Raspberry Pi 5)

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