.. | ||
bin | ||
lib | ||
src | ||
LICENSE | ||
package.json | ||
README.md |
lookpath
To check if the command exists and where the executable file is.
const { lookpath } = require('lookpath');
const p = await lookpath('bash');
// "/bin/bash", otherwise "undefined"
Install
npm install lookpath
Background
- I DON'T want to spawn
child_process
JUST 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.
Options
const { lookpath } = require('lookpath');
const p = await lookpath('bash', { include: ['/home/hiromu/.bin'], exclude: ['/mnt'] });
// include: Do scan also under `~/.bin`
// exclude: Do not scan under `/mnt`
Issues
Any feedback would be appreciated ;)