npm-path
Get a PATH containing locally installed module executables.
npm-path
will get you a PATH with all of the executables available to npm scripts, without booting up all of npm(1).
npm-path
will set your PATH to include:
- All of the
node_modules/.bin
directories from the current directory, up through all of its parents. This allows you to invoke the executables for any installed modules. e.g. if mocha
is installed a dependency of the current module, then mocha
will be available on a npm-path
generated $PATH
. - The directory containing the current
node
executable, so any scripts that invoke node
will execute the same node
. - Current npm's
node-gyp
directory, so the node-gyp
bundled with npm
can be used.
Usage
Command-line
> npm-path
Calling npm-path
from the commandline is the equivalent of executing an npm script with the body echo $PATH
, but without all of the overhead of booting or depending on npm
.
Set PATH
This will set the augmented PATH for the current process environment, or an environment you supply.
var npmPath = require('npm-path')
var PATH = npmPath.PATH
npmPath(function(err, $PATH) {
console.log(process.env[PATH] == $PATH)
console.log($PATH)
})
npmPath.set(function(err, $PATH) {
})
Synchronous Alternative
var $PATH = npmPath()
console.log($PATH)
$PATH = npmPath.setSync()
Optional Options
var options = {
env: process.env,
cwd: process.cwd()
}
npmPath(options, function(err, $PATH) {
})
npmPath.setSync(options)
Get PATH
This will get npm augmented PATH, but does not modify the PATH in the environment.
Takes the exact same options as set
.
npmPath.get(function(err, $PATH) {
console.log($PATH)
console.log(process.env[PATH] == $PATH)
})
npmPath.get(options, function(err, $PATH) {
console.log($PATH)
})
Synchronous Alternative
var $PATH = npmPath.get()
console.log($PATH)
console.log(process.env[PATH] == $PATH)
$PATH = npmPath.getSync()
Options
Both set
and get
take an optional options object, with optional env
& cwd
keys.
- Set
options.env
if you wish to use something other than process.env
(the default) - Set
options.cwd
if you wish to use something other than process.cwd()
(the default)
There's also a options.npm
property which you can set if you want node-gyp
to be sourced from
an alternative npm
installation.
Get the PATH environment variable key
npmPath.PATH
npmPath.PATH
Example Usage
process.env[npmPath.PATH]
process.env[npmPath.PATH] = npmPath.get()
npmPath()
Get the PATH separator
npmPath.SEPARATOR
npmPath.SEPARATOR
Credit
Path lookup code adapted directly from npm.
License
MIT