lookpath
v1.2.2
Published
The minimum and most straightforward way to check if command exists and where the executable is.
Downloads
170,847
Readme
lookpath
To check if the command exists and where the executable file is, WITHOUT using child_process
.
npm install lookpath
Example usage
const { lookpath } = require('lookpath');
const p = await lookpath('bash');
// "/bin/bash", otherwise "undefined"
Advanced usage
const p = await lookpath('bash', {
include: ['/home/hiromu/.bin'],
exclude: ['/mnt']
});
// include: Do scan also under `~/.bin`
// exclude: Do NOT scan under `/mnt`
Motivation
- I don't want to spawn
child_process
in order to kickwhich
,where
,whereis
, orcommand -v
. - then I checked Go implementation of
exec.LookPath
. - so I concluded that scanning under
$PATH
or$Path
is the best straightforward way to check if the command exists.
Issues
- https://github.com/otiai10/lookpath/issues
Any feedback would be appreciated ;)