# @d-fischer/detect-node

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

Latest version **3.0.1** (published 2022-05-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @d-fischer/detect-node
pnpm add @d-fischer/detect-node
yarn add @d-fischer/detect-node
bun add @d-fischer/detect-node
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2022-05-10 |
| First published | 2022-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ilya Kantor |
| Maintainers | d-fischer |
| Keywords | detect, node |

## Links

- npm: https://www.npmjs.com/package/@d-fischer/detect-node
- Repository: https://github.com/d-fischer/detect-node
- Homepage: https://github.com/iliakan/detect-node
- Issues: https://github.com/iliakan/detect-node/issues
- npm.io page: https://npm.io/package/@d-fischer/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

- 3.0.1 (latest) — 2022-05-10
- 3.0.0 — 2022-05-10

## 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/@d-fischer/detect-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
