time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

readme.md (2850B)


      1 # npm-run-path
      2 
      3 > Get your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) prepended with locally installed binaries
      4 
      5 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.
      6 
      7 ## Install
      8 
      9 ```sh
     10 npm install npm-run-path
     11 ```
     12 
     13 ## Usage
     14 
     15 ```js
     16 import childProcess from 'node:child_process';
     17 import {npmRunPath, npmRunPathEnv} from 'npm-run-path';
     18 
     19 console.log(process.env.PATH);
     20 //=> '/usr/local/bin'
     21 
     22 console.log(npmRunPath());
     23 //=> '/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'
     24 
     25 // `foo` is a locally installed binary
     26 childProcess.execFileSync('foo', {
     27 	env: npmRunPathEnv()
     28 });
     29 ```
     30 
     31 ## API
     32 
     33 ### npmRunPath(options?)
     34 
     35 Returns the augmented PATH string.
     36 
     37 #### options
     38 
     39 Type: `object`
     40 
     41 ##### cwd
     42 
     43 Type: `string | URL`\
     44 Default: `process.cwd()`
     45 
     46 The working directory.
     47 
     48 ##### path
     49 
     50 Type: `string`\
     51 Default: [`PATH`](https://github.com/sindresorhus/path-key)
     52 
     53 The PATH to be appended.
     54 
     55 Set it to an empty string to exclude the default PATH.
     56 
     57 ##### execPath
     58 
     59 Type: `string`\
     60 Default: `process.execPath`
     61 
     62 The path to the current Node.js executable. Its directory is pushed to the front of PATH.
     63 
     64 This can be either an absolute path or a path relative to the [`cwd` option](#cwd).
     65 
     66 ### npmRunPathEnv(options?)
     67 
     68 Returns the augmented [`process.env`](https://nodejs.org/api/process.html#process_process_env) object.
     69 
     70 #### options
     71 
     72 Type: `object`
     73 
     74 ##### cwd
     75 
     76 Type: `string | URL`\
     77 Default: `process.cwd()`
     78 
     79 The working directory.
     80 
     81 ##### env
     82 
     83 Type: `object`
     84 
     85 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.
     86 
     87 ##### execPath
     88 
     89 Type: `string`\
     90 Default: `process.execPath`
     91 
     92 The path to the Node.js executable to use in child processes if that is different from the current one. Its directory is pushed to the front of PATH.
     93 
     94 This can be either an absolute path or a path relative to the [`cwd` option](#cwd).
     95 
     96 ## Related
     97 
     98 - [npm-run-path-cli](https://github.com/sindresorhus/npm-run-path-cli) - CLI for this module
     99 - [execa](https://github.com/sindresorhus/execa) - Execute a locally installed binary
    100 
    101 ---
    102 
    103 <div align="center">
    104 	<b>
    105 		<a href="https://tidelift.com/subscription/pkg/npm-npm-run-path?utm_source=npm-npm-run-path&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
    106 	</b>
    107 	<br>
    108 	<sub>
    109 		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
    110 	</sub>
    111 </div>