npm-run-path
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
path-key | 3.1.1 | 2.21 kB | MIT | prod |
The npm-run-path is a useful npm package, designed to prepend your PATH with locally installed binaries. In npm run scripts, you can execute locally installed binaries by name. The npm-run-path package facilitates this functionality outside of npm. This increases flexibility and ease of use in script execution, making it an essential tool for many JavaScript developers.
You can use npm-run-path in your JavaScript project by first installing the package with npm using the command npm install npm-run-path
. Once installed, you can import the functions from the package into your JavaScript file. The package provides two primary functions: npmRunPath()
and npmRunPathEnv()
.
The npmRunPath()
function returns an augmented PATH string that includes the paths to locally installed binaries. The npmRunPathEnv()
function returns an augmented process.env
object, which includes the modified PATH.
Here is a simple usage example:
import childProcess from 'node:child_process';
import {npmRunPath, npmRunPathEnv} from 'npm-run-path';
console.log(process.env.PATH);
//=> '/usr/local/bin'
console.log(npmRunPath());
// Output includes paths to local binaries
// `foo` is a locally installed binary
childProcess.execFileSync('foo', {
env: npmRunPathEnv()
});
This script uses childProcess.execFileSync
to run a locally installed binary named 'foo', prepending the PATH with binary locations using npmRunPathEnv()
.
The primary source of documentation for the npm-run-path package is its README file, found in its repository on GitHub at git+https://github.com/sindresorhus/npm-run-path.git. The README provides a comprehensive guide on how to install and use the package, along with detailed information about the API and available options for customizing the package's behavior. Also, more insights can be gathered from the source code and from the npm-run-path-cli, a related package that provides a command-line interface for npm-run-path.