To check if the command exists and where the executable file is, WITHOUT using child_process.
npm install lookpath
const { lookpath } = require('lookpath');
const p = await lookpath('bash');
// "/bin/bash", otherwise "undefined"const p = await lookpath('bash', {
include: ['/home/hiromu/.bin'],
exclude: ['/mnt']
});
// include: Do scan also under `~/.bin`
// exclude: Do NOT scan under `/mnt`- I don't want to spawn
child_processin order to kickwhich,where,whereis, orcommand -v. - then I checked Go implementation of
exec.LookPath. - so I concluded that scanning under
$PATHor$Pathis the best straightforward way to check if the command exists.
Any feedback would be appreciated ;)