10

Hello im making a node app that requires: ffmpeg, node-acoutstid with fpcalc and eye3D. Now is my question how i can see if those 'programs' are installed on the clients machine.

whats the best way to check this ?

Nicolai
  • 133
  • 1
  • 8
  • Possible duplicate http://stackoverflow.com/questions/11600684/check-if-a-node-js-module-is-available – Yi Kai May 20 '17 at 01:52
  • @YiKai no thats not what im looking for im looking for a way to see if X program is installed on the machine for example see if is installed – Nicolai May 20 '17 at 08:09
  • You can use nodejs child_process.exec to run a shell command, http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script – Yi Kai May 20 '17 at 08:55

1 Answers1

11

"shell out" for native detection

In macOS / Linux / bash we'd typically use command -v (Posix compliant) or type -p or which (but don't use those).

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 promise
commandExists('ls').then(function (command) {
  // proceed
}).catch(function () {
  // command doesn't exist
});
coolaj86
  • 74,004
  • 20
  • 105
  • 125
  • [command-exists](https://github.com/mathisonian/command-exists) npm module has been forked and updated to address this [issue](https://github.com/mathisonian/command-exists/issues/22). its now [command-exists-promise](https://github.com/raftario/command-exists) – kinghat Feb 18 '20 at 21:29