# detect-node-es

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

Latest version **1.1.0** (published 2021-03-18) · MIT license · 0 weekly downloads

## Install

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

## 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 | 1.1.0 |
| Published | 2021-03-18 |
| First published | 2020-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Ilya Kantor |
| Maintainers | kashey |
| Keywords | detect, node |

## Links

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

## 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

- 1.1.0 (latest) — 2021-03-18
- 1.0.0 — 2020-07-27

## README

## detect-node
> This is a fork of `detect-node`.

Differences:
- uses named export {isNode}
- has d.ts integrated
- supports ESM

### Install

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

### Usage:

```diff
-var isNode = require('detect-node');
+var {isNode} = require('detect-node-es');

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-es · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
