提交学习笔记专用
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.

51 lines
1.3 KiB

  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. const which = require('which')
  9. // async usage
  10. // rejects if not found
  11. const resolved = await which('node')
  12. // if nothrow option is used, returns null if not found
  13. const resolvedOrNull = await which('node', { nothrow: true })
  14. // sync usage
  15. // throws if not found
  16. const resolved = which.sync('node')
  17. // if nothrow option is used, returns null if not found
  18. const resolvedOrNull = which.sync('node', { nothrow: true })
  19. // Pass options to override the PATH and PATHEXT environment vars.
  20. await which('node', { path: someOtherPath, pathExt: somePathExt })
  21. ```
  22. ## CLI USAGE
  23. Just like the BSD `which(1)` binary but using `node-which`.
  24. ```
  25. usage: node-which [-as] program ...
  26. ```
  27. You can learn more about why the binary is `node-which` and not `which`
  28. [here](https://github.com/npm/node-which/pull/67)
  29. ## OPTIONS
  30. You may pass an options object as the second argument.
  31. - `path`: Use instead of the `PATH` environment variable.
  32. - `pathExt`: Use instead of the `PATHEXT` environment variable.
  33. - `all`: Return all matches, instead of just the first one. Note that
  34. this means the function returns an array of strings instead of a
  35. single string.