Detect if executable exists on system path with node Detect if executable exists on system path with node unix unix

Detect if executable exists on system path with node


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.


You have to find a way to do it, as there is no "generic" or "out-of-box" way to do it.

One way is, you can use check if the desired package/binary is installed via your package manager then you can use utility whereis which attempts to locate the desired program in a list of standard Linux places, listed in $PATH.

Of course you can use also the utility which but whereis provides a bit more information. You can check about the difference of which and whereis here.

Generally speaking, as in your example, user might has manually installed some package at some random location, but not listed in $PATH.In this way there is no way to check if the package is installed at all, rather than to try to find the binary name or related files in complete tree of file system.