Node see if Program is installed Node see if Program is installed node.js node.js

Node see if Program is installed


"shell out" for native detection

In macOS / Linux / bash we'd typically use type -p or command -v (or which if you're doing it wrong).

In windows there's where that you can use like where node.exe.

require('child_process').exec('type -p mything', function (err, stdout) {  console.log(stdout);});

This naive approach can work if you're not trying to be cross-platform compatible and if you don't have to worry about sanitizing user input.

Use command-exists

On npm there's a package command-exists. I peeked at the code and it looks like it's probably the simplest cross-platform detection that covers edge cases at a small size:

https://github.com/mathisonian/command-exists/blob/master/lib/command-exists.js

var commandExists = require('command-exists');// invoked without a callback, it returns a promisecommandExists('ls').then(function (command) {  // proceed}).catch(function () {  // command doesn't exist});