{"id":18621,"library":"npm-which","title":"npm-which","description":"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.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/timoxley/npm-which","tags":["javascript","npm","path","executable","run"],"install":[{"cmd":"npm install npm-which","lang":"bash","label":"npm"},{"cmd":"yarn add npm-which","lang":"bash","label":"yarn"},{"cmd":"pnpm add npm-which","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is CommonJS but can be imported with ESM syntax in modern Node. The default export is a function.","wrong":"const npmWhich = require('npm-which')","symbol":"npmWhich","correct":"import npmWhich from 'npm-which'"},{"note":"sync is a method on the instance, not a named export.","wrong":"import { sync } from 'npm-which'","symbol":"sync","correct":"const which = require('npm-which')(cwd); const result = which.sync(name)"},{"note":"The default export returns a function that can be called with a callback for async usage.","wrong":"import { async } from 'npm-which'","symbol":"async","correct":"const which = require('npm-which')(cwd); which(name, callback)"}],"quickstart":{"code":"import npmWhich from 'npm-which';\n\nconst cwd = process.cwd();\nconst which = npmWhich(cwd);\n\n// Async\nwhich('tape', (err, path) => {\n  if (err) console.error(err.message);\n  else console.log(path);\n});\n\n// Sync\nconst pathToTape = which.sync('tape');\nconsole.log(pathToTape);\n\n// CLI: npm-which tape","lang":"typescript","description":"Shows programmatic usage (async and sync) and CLI invocation."},"warnings":[{"fix":"Use require('npm-which')(cwd) instead of require('npm-which').","message":"v2 removed the default export of a string; you must call require('npm-which')(cwd) to get the which function.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Call npmWhich(cwd) instead of npmWhich()(name, {cwd}).","message":"Passing cwd as second argument (options.cwd) is deprecated in favor of supplying it to the factory function.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Always provide cwd: const which = require('npm-which')(process.cwd());","message":"cwd is required. If omitted, the function throws an error.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use which(1) for global executables.","message":"The package does not search global node_modules; only local hierarchy.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"For multiple results, consider a different tool or iterate over PATH manually.","message":"The function returns the first match, not all matches.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"const which = require('npm-which')(cwd); then which(name);","cause":"Calling the imported package as a function without providing cwd first.","error":"TypeError: which is not a function"},{"fix":"Pass a cwd string: require('npm-which')(__dirname);","cause":"Calling require('npm-which')() without arguments.","error":"Error: cwd is required"},{"fix":"Install the package locally: npm install tape; or ensure it is in a parent node_modules.","cause":"The executable is not installed in any node_modules in the hierarchy.","error":"Error: Cannot find module 'tape'"},{"fix":"npm install -g npm-which","cause":"The package is not installed globally.","error":"npm-which: command not found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}