# npm-run-path

> Get your PATH prepended with locally installed binaries

Latest version **6.0.0** (published 2024-08-26) · MIT license · 0 weekly downloads

## Install

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

## 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 | 6.0.0 |
| Published | 2024-08-26 |
| First published | 2015-12-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 108 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | npm, run, path, package, bin, binary, binaries, script, cli, command-line, execute, executable |

## Links

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

## Dependencies (2)

- [path-key](https://npm.io/package/path-key.md) ^4.0.0
- [unicorn-magic](https://npm.io/package/unicorn-magic.md) ^0.3.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 6.0.0 (latest) — 2024-08-26
- 5.3.0 — 2024-02-23
- 5.2.0 — 2023-12-21
- 5.1.0 — 2022-02-09
- 5.0.1 — 2021-10-05
- 5.0.0 — 2021-10-05
- 4.0.1 — 2019-12-22
- 4.0.0 — 2019-10-14
- 3.1.0 — 2019-04-05
- 3.0.0 — 2019-03-10
- 2.0.2 — 2016-09-29
- 2.0.1 — 2016-09-28
- 2.0.0 — 2016-09-25
- 1.0.0 — 2015-12-28

## README

# npm-run-path

> Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries

In [npm run scripts](https://docs.npmjs.com/cli/run-script) you can execute locally installed binaries by name. This enables the same outside npm.

## Install

```sh
npm install npm-run-path
```

## Usage

```js
import childProcess from 'node:child_process';
import {npmRunPath, npmRunPathEnv} from 'npm-run-path';

console.log(process.env.PATH);
//=> '/usr/local/bin'

console.log(npmRunPath());
//=> '/Users/sindresorhus/dev/foo/node_modules/.bin:/Users/sindresorhus/dev/node_modules/.bin:/Users/sindresorhus/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/usr/local/bin'

// `foo` is a locally installed binary
childProcess.execFileSync('foo', {
	env: npmRunPathEnv()
});
```

## API

### npmRunPath(options?)

`options`: [`Options`](#options)\
_Returns_: `string`

Returns the augmented PATH string.

### npmRunPathEnv(options?)

`options`: [`Options`](#options)\
_Returns_: `object`

Returns the augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object.

### options

Type: `object`

#### cwd

Type: `string | URL`\
Default: `process.cwd()`

The working directory.

#### execPath

Type: `string | URL`\
Default: [`process.execPath`](https://nodejs.org/api/process.html#processexecpath)

The path to the current Node.js executable.

This can be either an absolute path or a path relative to the [`cwd` option](#cwd).

#### addExecPath

Type: `boolean`\
Default: `true`

Whether to push the current Node.js executable's directory ([`execPath`](#execpath) option) to the front of PATH.

#### preferLocal

Type: `boolean`\
Default: `true`

Whether to push the locally installed binaries' directory to the front of PATH.

#### path

Type: `string`\
Default: [`PATH`](https://github.com/sindresorhus/path-key)

The PATH to be appended.

Set it to an empty string to exclude the default PATH.

Only available with [`npmRunPath()`](#npmrunpathoptions), not [`npmRunPathEnv()`](#npmrunpathenvoptions).

#### env

Type: `object`\
Default: [`process.env`](https://nodejs.org/api/process.html#processenv)

Accepts an object of environment variables, like `process.env`, and modifies the PATH using the correct [PATH key](https://github.com/sindresorhus/path-key). Use this if you're modifying the PATH for use in the `child_process` options.

Only available with [`npmRunPathEnv()`](#npmrunpathenvoptions), not [`npmRunPath()`](#npmrunpathoptions).

## Related

- [npm-run-path-cli](https://github.com/sindresorhus/npm-run-path-cli) - CLI for this module
- [execa](https://github.com/sindresorhus/execa) - Execute a locally installed binary

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