f104af9aae40ff3c30cc3c969988f60a672c07188e722c61c01a30fdd9dc316e6325e90ce4b8528ab8f2d0b18bbe338e3b2ee077185f36ce19eed512000fc4 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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)