• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# which
2
3Like the unix `which` utility.
4
5Finds the first instance of a specified executable in the PATH
6environment variable.  Does not cache the results, so `hash -r` is not
7needed when the PATH changes.
8
9## USAGE
10
11```javascript
12const which = require('which')
13
14// async usage
15// rejects if not found
16const resolved = await which('node')
17
18// if nothrow option is used, returns null if not found
19const resolvedOrNull = await which('node', { nothrow: true })
20
21// sync usage
22// throws if not found
23const resolved = which.sync('node')
24
25// if nothrow option is used, returns null if not found
26const resolvedOrNull = which.sync('node', { nothrow: true })
27
28// Pass options to override the PATH and PATHEXT environment vars.
29await which('node', { path: someOtherPath, pathExt: somePathExt })
30```
31
32## CLI USAGE
33
34Just like the BSD `which(1)` binary but using `node-which`.
35
36```
37usage: node-which [-as] program ...
38```
39
40You can learn more about why the binary is `node-which` and not `which`
41[here](https://github.com/npm/node-which/pull/67)
42
43## OPTIONS
44
45You may pass an options object as the second argument.
46
47- `path`: Use instead of the `PATH` environment variable.
48- `pathExt`: Use instead of the `PATHEXT` environment variable.
49- `all`: Return all matches, instead of just the first one.  Note that
50  this means the function returns an array of strings instead of a
51  single string.
52