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"npm install lookpath
- I DON'T want to spawn
child_processJUST in order to kickwhich,where,whereis, orcommand -v. - I checked Go implementation of
exec.LookPath. - I concluded that scanning under
$PATHor$Pathis the best straightforward way to check if the command exists.
Any feedback would be appreciated ;)