# Check if the code is running in NodeJS

Look for process.versions.node.

Canonical: https://1loc.dev/misc/check-if-the-code-is-running-in-node-js/
Version: 1.0.0
Runtime: Node.js 22
Verification: Usage lines executed in Node.js 22; no external services
Updated: 2026-10-28

## Implementation

```javascript
function isNode() { return typeof process !== 'undefined' && process.versions?.node != null; }
```

## Usage

```javascript
isNode(); // → true
```

Lines marked → were executed in Node.js 22, and each result was compared with the value shown. Lines marked e.g. are illustrative.

## Limits

- Node-compatible runtimes such as Bun also set process.versions.node, so this detects compatibility, not Node.js itself. The browser tests confirm it returns false in Chromium.
- Prefer feature detection (does the API you need exist?) over runtime detection.

The function does not validate its arguments. Add checks where it receives untrusted input.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/check-if-the-code-is-running-in-node-js.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Documented as a reference with executed usage lines. Original MDX retained as inert source evidence.
