You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

4 years ago
  1. # which
  2. Like the unix `which` utility.
  3. Finds the first instance of a specified executable in the PATH
  4. environment variable. Does not cache the results, so `hash -r` is not
  5. needed when the PATH changes.
  6. ## USAGE
  7. ```javascript
  8. var which = require('which')
  9. // async usage
  10. which('node', function (er, resolvedPath) {
  11. // er is returned if no "node" is found on the PATH
  12. // if it is found, then the absolute path to the exec is returned
  13. })
  14. // or promise
  15. which('node').then(resolvedPath => { ... }).catch(er => { ... not found ... })
  16. // sync usage
  17. // throws if not found
  18. var resolved = which.sync('node')
  19. // if nothrow option is used, returns null if not found
  20. resolved = which.sync('node', {nothrow: true})
  21. // Pass options to override the PATH and PATHEXT environment vars.
  22. which('node', { path: someOtherPath }, function (er, resolved) {
  23. if (er)
  24. throw er
  25. console.log('found at %j', resolved)
  26. })
  27. ```
  28. ## CLI USAGE
  29. Same as the BSD `which(1)` binary.
  30. ```
  31. usage: which [-as] program ...
  32. ```
  33. ## OPTIONS
  34. You may pass an options object as the second argument.
  35. - `path`: Use instead of the `PATH` environment variable.
  36. - `pathExt`: Use instead of the `PATHEXT` environment variable.
  37. - `all`: Return all matches, instead of just the first one. Note that
  38. this means the function returns an array of strings instead of a
  39. single string.