# run-node

> Run the Node.js binary no matter what

Latest version **3.0.0** (published 2025-09-15) · MIT license · 0 weekly downloads

## Install

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

Provides the commands `run-npx`, `run-node`.

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2025-09-15 |
| First published | 2016-07-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 142 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | run, node, nodejs, node.js, npx, npm, find, binary, bin, execute, which, detect, path, env, bash, shell, sh |

## Links

- npm: https://www.npmjs.com/package/run-node
- Repository: https://github.com/sindresorhus/run-node
- Homepage: https://github.com/sindresorhus/run-node#readme
- Issues: https://github.com/sindresorhus/run-node/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/run-node

## Alternatives

- [replicas-cli](https://npm.io/package/replicas-cli.md) — 3.0K weekly downloads
- [env-contract](https://npm.io/package/env-contract.md) — 133 weekly downloads
- [@openveo/api](https://npm.io/package/@openveo/api.md) — 61 weekly downloads
- [@ryniaubenpm2/cumque-error-reiciendis](https://npm.io/package/@ryniaubenpm2/cumque-error-reiciendis.md) — 54 weekly downloads
- [ts-global-type-extra](https://npm.io/package/ts-global-type-extra.md) — 11 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2025-09-15
- 2.0.0 — 2020-02-22
- 1.0.0 — 2018-04-19
- 0.2.0 — 2018-01-14
- 0.1.1 — 2016-07-16
- 0.1.0 — 2016-07-16

## README

# run-node

> Run the Node.js binary no matter what

You can't always assume running `$ node file.js` will just work. The user might have the `node` binary in a non-standard location. They might be using a Node.js version manager like `nvm`, which is sourced in a subshell and not available from the outside. Or they might have `node` installed as a local dependency in an npm project. It also depends from where you're trying to run it. For example, GUI apps on macOS doesn't inherit the [`$PATH`](https://en.wikipedia.org/wiki/PATH_(variable)), so the `node` binary would not be found. Most projects that depend on Node.js just end up telling the user to manually set the full path to the `node` binary in some project specific settings. Now every project has to do this. [Ugh...](https://gist.github.com/cookrn/4015437) I prefer things to *just* work. With this module it will.

This Bash script uses some tricks to find the Node.js binary on your system and run it. A companion `run-npx` script is also provided to reliably run `npx`.

Can be used from any environment that can spawn a process (Shell, Python, Ruby, Swift, Objective-C, etc).

### npm

#### Install

```sh
npm install run-node
```

#### Usage

```sh
./node_modules/.bin/run-node file.js
```

Or in an [npm run script](https://docs.npmjs.com/cli/run-script):

```json
{
	"start": "run-node file.js"
}
```

To run `npx` commands:

```sh
./node_modules/.bin/run-npx package-name
```

When run within an npm script context, `run-node` will use the same Node.js binary that npm is using (via the `npm_node_execpath` environment variable), ensuring consistency with the parent process. When run directly outside of npm scripts, if the [`node`](https://www.npmjs.com/package/node) package is found in the local `node_modules` directory, that binary will be used instead.

### Manually

#### Install

Download the [run-node](run-node) file:

```sh
curl -sSLO https://github.com/sindresorhus/run-node/raw/main/run-node && chmod +x run-node
```

For `npx` support, also download [run-npx](run-npx):

```sh
curl -sSLO https://github.com/sindresorhus/run-node/raw/main/run-npx && chmod +x run-npx
```

#### Usage

```sh
./run-node file.js
```

Or with `npx`:

```sh
./run-npx package-name
```

#### Customizable cache path and error message

The cache path and error message are defined by the `RUN_NODE_CACHE_PATH` and `RUN_NODE_ERROR_MSG` environment variables. You could use them in a script or add them to your `~.bashrc`.

Default config:

```sh
export RUN_NODE_ERROR_MSG="Couldn't find the Node.js binary. Ensure you have Node.js installed. Open an issue on https://github.com/sindresorhus/run-node"
export RUN_NODE_CACHE_PATH="/home/username/.node_path"
```

If the `RUN_NODE_CACHE_PATH` environment variable is defined explicitly, the script it points to will be sourced before looking for a `node` binary. You can use this script to override your `PATH` variable so that a specific `node` binary is found.

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