which-promise is a JavaScript utility library that provides a Promise-based API for locating executable programs within a user's system `PATH` environment variable. It functions as a direct, promisified wrapper around the robust and widely used `node-which` library, offering a modern, asynchronous interface to a fundamental system operation. The package is currently at version 1.0.0, indicating a stable and mature API that is unlikely to see frequent breaking changes. As a wrapper, its release cadence is closely tied to updates and bug fixes in its underlying dependency, `node-which`, primarily focusing on stability and compatibility across different Node.js versions and operating systems. Its primary differentiator is simplifying the asynchronous lookup of executables by leveraging native JavaScript Promises, making it straightforward to integrate into contemporary `async/await` workflows, which is a significant improvement over traditional callback-based approaches. It is particularly valuable in Node.js development for scripting, tooling, and applications that require programmatic discovery of system binaries.
npm install which-promiseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `which-promise` to asynchronously locate common executables like 'node' and 'npm' in the system's PATH, and handles the case where a command is not found.
For ESM projects, use `const whichPromise = require('which-promise');` if within `createRequire`, or consider dynamic `import('which-promise').then(m => m.default)`. For most direct usage in Node.js, stick to `const whichPromise = require('which-promise');`.Ensure the `PATH` environment variable is correctly set for your operating system and user. When `which-promise` returns 'not found', it indicates the command is not accessible via the configured `PATH`.
Refer to the documentation for `node-which` (github.com/npm/node-which) for detailed information on platform-specific behaviors or advanced options that can be passed through `which-promise`'s `options` argument.
Replace `const whichPromise = require('which-promise');` with `const which = require('which'); const whichPromise = require('util').promisify(which);`Verify that the command-name is correctly spelled and that its containing directory is included in your system's PATH. On Linux/macOS, check file permissions with `ls -l $(which command-name)`. You can also provide a custom `path` option to `whichPromise(cmd, { path: '/custom/bin' })`.Ensure you are using the correct CommonJS `require` syntax: `const whichPromise = require('which-promise');`. If in an ESM module, consider dynamic import (`import('which-promise').then(m => m)`) or `createRequire`.Ensure all dependencies are compatible with your module system. If `which-promise` or `node-which` ever transitions to ESM-only, you would need to adjust your project to use ESM `import` statements or dynamic `import()` where appropriate.