Registry / devops / npm-which

npm-which

JSON →
library3.0.1jsnpmunverified

Locates executables from locally or parent-installed node modules, similar to `which` but respecting npm's PATH. Version 3.0.1 is stable with no recent releases. Key differentiator: it is faster than shelling out to `npm bin` and works across the node_modules hierarchy, not just the current directory. Supports both async and sync APIs, and a CLI. Requires Node >=4.2.0, no runtime dependencies.

npm install npm-which
INSTALL
IMPORT
SIG · NPM-WHICH
N
npm-which
devopsjavascriptv3.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

npmWhich
import npmWhich from 'npm-which'
const npmWhich = require('npm-which')
Package is CommonJS but can be imported with ESM syntax in modern Node. The default export is a function.
sync
const which = require('npm-which')(cwd); const result = which.sync(name)
import { sync } from 'npm-which'
sync is a method on the instance, not a named export.
async
const which = require('npm-which')(cwd); which(name, callback)
import { async } from 'npm-which'
The default export returns a function that can be called with a callback for async usage.

Shows programmatic usage (async and sync) and CLI invocation.

import npmWhich from 'npm-which'; const cwd = process.cwd(); const which = npmWhich(cwd); // Async which('tape', (err, path) => { if (err) console.error(err.message); else console.log(path); }); // Sync const pathToTape = which.sync('tape'); console.log(pathToTape); // CLI: npm-which tape
npm-which --version
Debug
Known issues
breakingv2 removed the default export of a string; you must call require('npm-which')(cwd) to get the which function.
fix
Use require('npm-which')(cwd) instead of require('npm-which').
affects: >=2.0.0
deprecatedPassing cwd as second argument (options.cwd) is deprecated in favor of supplying it to the factory function.
fix
Call npmWhich(cwd) instead of npmWhich()(name, {cwd}).
affects: >=3.0.0
gotchacwd is required. If omitted, the function throws an error.
fix
Always provide cwd: const which = require('npm-which')(process.cwd());
affects: >=2.0.0
gotchaThe package does not search global node_modules; only local hierarchy.
fix
Use which(1) for global executables.
affects: >=0.0.0
gotchaThe function returns the first match, not all matches.
fix
For multiple results, consider a different tool or iterate over PATH manually.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: which is not a function
Calling the imported package as a function without providing cwd first.
fix
const which = require('npm-which')(cwd); then which(name);
Error: cwd is required
Calling require('npm-which')() without arguments.
fix
Pass a cwd string: require('npm-which')(__dirname);
Error: Cannot find module 'tape'
The executable is not installed in any node_modules in the hierarchy.
fix
Install the package locally: npm install tape; or ensure it is in a parent node_modules.
npm-which: command not found
The package is not installed globally.
fix
npm install -g npm-which
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
npm-which — npm install npm-which · libregistry