real-executable-path-callback
Version:
Callback style version of real-executable-path
65 lines (43 loc) • 2.53 kB
Markdown
# real-executable-path-callback
[](https://www.npmjs.com/package/real-executable-path-callback)
[](https://travis-ci.org/shinnn/real-executable-path-callback)
[](https://ci.appveyor.com/project/ShinnosukeWatanabe/real-executable-path-callback/branch/master)
[](https://coveralls.io/github/shinnn/real-executable-path-callback)
[Callback](http://thenodeway.io/posts/understanding-error-first-callbacks/)-style version of [real-executable-path]:
> Find the first instance of an executable in the PATH, with expanding all symbolic links
```javascript
const realExecutablePathCallback = require('real-executable-path-callback');
const which = require('which');
which('npm', (err, binPath) => {
binPath; //=> '/usr/local/bin/npm'
});
realExecutablePathCallback('npm', (err, binPath) => {
binPath; //=> '/usr/local/lib/node_modules/npm/bin/npm-cli.js'
});
```
## Installation
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).
```
npm install real-executable-path-callback
```
## API
```javascript
const realExecutablePathCallback = require('real-executable-path-callback');
```
### realExecutablePathCallback(*binName* [, *options*], *callback*)
*binName*: `string` (an executable name in the PATH)
*options*: `Object` ([`node-which` options](https://github.com/npm/node-which#options) except for `all`)
*callback*: `Function` (called after the path is resolved)
It finds the first instance of the given executable in the [PATH](http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html#tag_08_03) environment variable, expands all symbolic links and resolves the canonicalized absolute pathname.
```javascript
const realExecutablePathCallback = require('real-executable-path-callback');
realExecutablePathCallback('this_cmd_is_not_installed', err => {
err.message; //=> 'not found: this_cmd_is_not_installed'
err.code; //=> 'ENOENT'
});
```
## Related project
* [real-executable-path] — [Promise](https://promisesaplus.com/) version
## License
[ISC License](./LICENSE) © 2017 Shinnosuke Watanabe
[real-executable-path]: https://github.com/shinnn/real-executable-path