Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node see if Program is installed

Tags:

node.js

ffmpeg

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 ?

like image 547
Nicolai Avatar asked May 19 '17 09:05

Nicolai


People also ask

How do I know if a package is installed in node?

Use the npm list to show the installed packages in the current project as a dependency tree. Use npm list --depth=n to show the dependency tree with a specified depth. Use npm list --prod to show packages in the dependencies . Use npm list --dev to show packages in the devDependencies .

How do I know if Node.js is installed in Visual Studio code?

To test that you have Node. js installed correctly on your computer, open a new terminal and type node --version and you should see the current Node. js version installed.

How do you check NPM is installed or not?

To see if NPM is installed, type npm -v in Terminal. This should print the version number so you'll see something like this 1.4.


1 Answers

"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 promise
commandExists('ls').then(function (command) {
  // proceed
}).catch(function () {
  // command doesn't exist
});
like image 99
coolaj86 Avatar answered Oct 18 '22 03:10

coolaj86