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.

81 lines
1.8 KiB

4 years ago
  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. > Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries
  3. 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.
  4. ## Install
  5. ```
  6. $ npm install --save npm-run-path
  7. ```
  8. ## Usage
  9. ```js
  10. const childProcess = require('child_process');
  11. const npmRunPath = require('npm-run-path');
  12. console.log(process.env.PATH);
  13. //=> '/usr/local/bin'
  14. console.log(npmRunPath());
  15. //=> '/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'
  16. // `foo` is a locally installed binary
  17. childProcess.execFileSync('foo', {
  18. env: npmRunPath.env()
  19. });
  20. ```
  21. ## API
  22. ### npmRunPath([options])
  23. #### options
  24. ##### cwd
  25. Type: `string`<br>
  26. Default: `process.cwd()`
  27. Working directory.
  28. ##### path
  29. Type: `string`<br>
  30. Default: [`PATH`](https://github.com/sindresorhus/path-key)
  31. PATH to be appended.<br>
  32. Set it to an empty string to exclude the default PATH.
  33. ### npmRunPath.env([options])
  34. #### options
  35. ##### cwd
  36. Type: `string`<br>
  37. Default: `process.cwd()`
  38. Working directory.
  39. ##### env
  40. Type: `Object`
  41. 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.
  42. ## Related
  43. - [npm-run-path-cli](https://github.com/sindresorhus/npm-run-path-cli) - CLI for this module
  44. - [execa](https://github.com/sindresorhus/execa) - Execute a locally installed binary
  45. ## License
  46. MIT © [Sindre Sorhus](https://sindresorhus.com)