https://github.com/mswjs/is-node-process
Reliably determines if the code is running in Node.js. Treats Jest, React Native, Electron, and others like Node.js.
https://github.com/mswjs/is-node-process
check nodejs process
Last synced: about 1 year ago
JSON representation
Reliably determines if the code is running in Node.js. Treats Jest, React Native, Electron, and others like Node.js.
- Host: GitHub
- URL: https://github.com/mswjs/is-node-process
- Owner: mswjs
- Created: 2021-07-18T23:48:51.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-23T16:43:29.000Z (over 3 years ago)
- Last Synced: 2025-04-19T17:36:56.449Z (about 1 year ago)
- Topics: check, nodejs, process
- Language: TypeScript
- Homepage: https://npm.im/is-node-process
- Size: 110 KB
- Stars: 12
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/is-node-process)
# `is-node-process`
Reliably determines if the code is running in Node.js
## Motivation
This library was created to provide a reliable way of determining a Node.js process, taking into account:
- Browser-like environments (JSDOM);
- Electron renderer process;
- React Native runtime.
### Why relying on `window` is a bad idea
There are environments (i.e. JSDOM) that polyfill the global `window` object and some of its API for the sake of emulating browser-like behaviors, while still remaining a Node.js process.
### Why relying on `process` is a bad idea
Electron injects a global `process` object in the browser runtime when run with the `nodeIntegration: true` option.
## Getting started
```sh
$ npm install is-node-process
# or
$ yarn add is-node-process
```
```js
// any/code.js
const { isNodeProcess } = require('is-node-process')
isNodeProcess() // true/false
```