| 1 | # npm-run-path [](https://travis-ci.org/sindresorhus/npm-run-path)
|
|---|
| 2 |
|
|---|
| 3 | > Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries
|
|---|
| 4 |
|
|---|
| 5 | 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.
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | ## Install
|
|---|
| 9 |
|
|---|
| 10 | ```
|
|---|
| 11 | $ npm install npm-run-path
|
|---|
| 12 | ```
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | ## Usage
|
|---|
| 16 |
|
|---|
| 17 | ```js
|
|---|
| 18 | const childProcess = require('child_process');
|
|---|
| 19 | const npmRunPath = require('npm-run-path');
|
|---|
| 20 |
|
|---|
| 21 | console.log(process.env.PATH);
|
|---|
| 22 | //=> '/usr/local/bin'
|
|---|
| 23 |
|
|---|
| 24 | console.log(npmRunPath());
|
|---|
| 25 | //=> '/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'
|
|---|
| 26 |
|
|---|
| 27 | // `foo` is a locally installed binary
|
|---|
| 28 | childProcess.execFileSync('foo', {
|
|---|
| 29 | env: npmRunPath.env()
|
|---|
| 30 | });
|
|---|
| 31 | ```
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | ## API
|
|---|
| 35 |
|
|---|
| 36 | ### npmRunPath(options?)
|
|---|
| 37 |
|
|---|
| 38 | Returns the augmented path string.
|
|---|
| 39 |
|
|---|
| 40 | #### options
|
|---|
| 41 |
|
|---|
| 42 | Type: `object`
|
|---|
| 43 |
|
|---|
| 44 | ##### cwd
|
|---|
| 45 |
|
|---|
| 46 | Type: `string`<br>
|
|---|
| 47 | Default: `process.cwd()`
|
|---|
| 48 |
|
|---|
| 49 | Working directory.
|
|---|
| 50 |
|
|---|
| 51 | ##### path
|
|---|
| 52 |
|
|---|
| 53 | Type: `string`<br>
|
|---|
| 54 | Default: [`PATH`](https://github.com/sindresorhus/path-key)
|
|---|
| 55 |
|
|---|
| 56 | PATH to be appended.<br>
|
|---|
| 57 | Set it to an empty string to exclude the default PATH.
|
|---|
| 58 |
|
|---|
| 59 | ##### execPath
|
|---|
| 60 |
|
|---|
| 61 | Type: `string`<br>
|
|---|
| 62 | Default: `process.execPath`
|
|---|
| 63 |
|
|---|
| 64 | Path to the current Node.js executable. Its directory is pushed to the front of PATH.
|
|---|
| 65 |
|
|---|
| 66 | This can be either an absolute path or a path relative to the [`cwd` option](#cwd).
|
|---|
| 67 |
|
|---|
| 68 | ### npmRunPath.env(options?)
|
|---|
| 69 |
|
|---|
| 70 | Returns the augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object.
|
|---|
| 71 |
|
|---|
| 72 | #### options
|
|---|
| 73 |
|
|---|
| 74 | Type: `object`
|
|---|
| 75 |
|
|---|
| 76 | ##### cwd
|
|---|
| 77 |
|
|---|
| 78 | Type: `string`<br>
|
|---|
| 79 | Default: `process.cwd()`
|
|---|
| 80 |
|
|---|
| 81 | Working directory.
|
|---|
| 82 |
|
|---|
| 83 | ##### env
|
|---|
| 84 |
|
|---|
| 85 | Type: `Object`
|
|---|
| 86 |
|
|---|
| 87 | 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.
|
|---|
| 88 |
|
|---|
| 89 | ##### execPath
|
|---|
| 90 |
|
|---|
| 91 | Type: `string`<br>
|
|---|
| 92 | Default: `process.execPath`
|
|---|
| 93 |
|
|---|
| 94 | Path to the Node.js executable to use in child processes if that is different from the current one. Its directory is pushed to the front of PATH.
|
|---|
| 95 |
|
|---|
| 96 | This can be either an absolute path or a path relative to the [`cwd` option](#cwd).
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 | ## Related
|
|---|
| 100 |
|
|---|
| 101 | - [npm-run-path-cli](https://github.com/sindresorhus/npm-run-path-cli) - CLI for this module
|
|---|
| 102 | - [execa](https://github.com/sindresorhus/execa) - Execute a locally installed binary
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 | ---
|
|---|
| 106 |
|
|---|
| 107 | <div align="center">
|
|---|
| 108 | <b>
|
|---|
| 109 | <a href="https://tidelift.com/subscription/pkg/npm-npm-run-path?utm_source=npm-npm-run-path&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
|---|
| 110 | </b>
|
|---|
| 111 | <br>
|
|---|
| 112 | <sub>
|
|---|
| 113 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
|---|
| 114 | </sub>
|
|---|
| 115 | </div>
|
|---|