which
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
isexe | 2.0.0 | 3.67 kB | ISC | prod |
"Which" is a JavaScript package that mirrors the functionality of the Unix which
utility. It searches the PATH environment variable to find the first instance of a specified executable. Importantly, it does not cache the results, so there's no need to use hash -r
when the PATH changes, which means it always provides the current and accurate location (if any) of the specified tool or command in the system's PATH.
The "which" package is pretty straightforward to use in your JavaScript programs. You can incorporate it via require('which')
.
Here is an example of asynchronous usage:
const which = require('which')
// async usage
const resolved = await which('node')
// if nothrow option is used, returns null if not found
const resolvedOrNull = await which('node', { nothrow: true })
And synchronous usage:
const which = require('which')
// sync usage
const resolved = which.sync('node')
// if nothrow option is used, returns null if not found
const resolvedOrNull = which.sync('node', { nothrow: true })
You can also override the PATH and PATHEXT environment variables by passing an options object:
await which('node', { path: someOtherPath, pathExt: somePathExt })
It can also be used as a command-line interface tool, with syntax similar to the BSD which(1)
binary but through node-which
.
The official documentation for the which
package is available in the package's readme file on its GitHub repository. Here, you can learn more about its usage, options, and command-line interface: https://github.com/npm/node-which