UNPKG

1.89 kBMarkdownView Raw
1# npm-run-path [![Build Status](https://travis-ci.org/sindresorhus/npm-run-path.svg?branch=master)](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
5In [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 --save npm-run-path
12```
13
14
15## Usage
16
17```js
18const childProcess = require('child_process');
19const npmRunPath = require('npm-run-path');
20
21console.log(process.env.PATH);
22//=> '/usr/local/bin'
23
24console.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
28childProcess.execFileSync('foo', {
29 env: npmRunPath.env()
30});
31```
32
33
34## API
35
36### npmRunPath([options])
37
38#### options
39
40##### cwd
41
42Type: `string`<br>
43Default: `process.cwd()`
44
45Working directory.
46
47##### path
48
49Type: `string`<br>
50Default: [`PATH`](https://github.com/sindresorhus/path-key)
51
52PATH to be appended.<br>
53Set it to an empty string to exclude the default PATH.
54
55### npmRunPath.env([options])
56
57#### options
58
59##### cwd
60
61Type: `string`<br>
62Default: `process.cwd()`
63
64Working directory.
65
66##### env
67
68Type: `Object`
69
70Accepts 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.
71
72
73## Related
74
75- [npm-run-path-cli](https://github.com/sindresorhus/npm-run-path-cli) - CLI for this module
76- [execa](https://github.com/sindresorhus/execa) - Execute a locally installed binary
77
78
79## License
80
81MIT © [Sindre Sorhus](https://sindresorhus.com)