Is there a simple way to tell if a system executable is available on the system path using node? For example if a user has python installed at /usr/bin/python
and /usr/bin
is in $PATH
how can I detect that in Node? And conversely detect when something isn't installed or is just not on path, i.e. /usr/opt/local/mycustompath/python
? Ideally hoping their is an npm package available ...
I'm sure this is a quick google search with the right search term, but I'm failing due to the fact where and which are pretty generic search terms.
I'm working on some dev config for a node tool and would like to be able to detect whether python (or pip) is already available on path, and if not, ask the user to tell install it or tell us where to find it. I'm currently planning on doing this with where
on windows machines and which
on *nix machines, but was hoping there might be a single cross platform way of doing this.
Package hasbin has since been published to the npm registry, which provides this functionality:
Install it (as part of your project) with npm install hasbin
To test the availability of Python, use it as follows (do not append .exe
to the executable file name):
var isPyAvailable = require('hasbin').sync('python')
The package has various other helpful methods, such as the ability to find the first available binary among several - see its GitHub repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With