# detect-node

> Detect Node.JS (as opposite to browser environment) (reliable)

Latest version **2.1.0** (published 2021-05-16) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 28/100 (F)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2021-05-16 |
| First published | 2014-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/detect-node) |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 75 |
| Author | Ilya Kantor |
| Maintainers | iliakan |
| Keywords | detect, node |

## Links

- npm: https://www.npmjs.com/package/detect-node
- Repository: https://github.com/iliakan/detect-node
- Issues: https://github.com/iliakan/detect-node/issues
- npm.io page: https://npm.io/package/detect-node

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2021-05-16
- 2.0.5 — 2021-03-16
- 2.0.4 — 2018-08-31
- 2.0.3 — 2014-08-01
- 2.0.2 — 2014-07-31
- 2.0.1 — 2014-07-31
- 2.0.0 — 2014-07-31
- 1.0.0 — 2014-07-31

## README

### Install

```shell
npm install --save detect-node
```

### Usage:

```js
var isNode = require('detect-node');

if (isNode) {
  console.log("Running under Node.JS");
} else {
  alert("Hello from browser (or whatever not-a-node env)");
}
```

The check is performed as:
```js
module.exports = false;

// Only Node.JS has a process variable that is of [[Class]] process
try {
 module.exports = Object.prototype.toString.call(global.process) === '[object process]' 
} catch(e) {}

```

Thanks to Ingvar Stepanyan for the initial idea. This check is both **the most reliable I could find** and it does not use `process` env directly, which would cause browserify to include it into the build.

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