Projekt

Obecné

Profil

Stáhnout (1.85 KB) Statistiky
| Větev: | Revize:
1 3a515b92 cagy
# 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
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 --save 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
#### options
39
40
##### cwd
41
42
Type: `string`<br>
43
Default: `process.cwd()`
44
45
Working directory.
46
47
##### path
48
49
Type: `string`<br>
50
Default: [`PATH`](https://github.com/sindresorhus/path-key)
51
52
PATH to be appended.<br>
53
Set it to an empty string to exclude the default PATH.
54
55
### npmRunPath.env([options])
56
57
#### options
58
59
##### cwd
60
61
Type: `string`<br>
62
Default: `process.cwd()`
63
64
Working directory.
65
66
##### env
67
68
Type: `Object`
69
70
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.
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
81
MIT © [Sindre Sorhus](https://sindresorhus.com)