Alicia
Alicia

Reputation: 1161

How to get the full path of an executable which is in $PATH in node.js?

Is there a function in node.js to find an executable file which is located somewhere in the $PATH, similar to which builtin of Bash?

If not, I could always try to parse process.env.PATH and manually search in each directory, but I would rather avoid that if possible.

Upvotes: 3

Views: 4433

Answers (1)

Ben
Ben

Reputation: 5074

You might want to check out which module

var which = require('which');
which('ls', function(err, result) {
  console.log(result);   // prints '/bin/ls' on mac 
});

Upvotes: 13

Related Questions