Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a file is executable in node.js?

How do I check if a file is executable in node.js?

Maybe something like

fs.isExecutable(function (isExecutable) {

})
like image 597
Drew LeSueur Avatar asked Apr 28 '13 01:04

Drew LeSueur


1 Answers

Another option that relies only on the built-in fs module is to use either fs.access or fs.accessSync. This method is easier than getting and parsing the file mode. An example:

const fs = require('fs');

fs.access('./foobar.sh', fs.constants.X_OK, (err) => {
    console.log(err ? 'cannot execute' : 'can execute');
});
like image 180
Danny Guo Avatar answered Oct 19 '22 17:10

Danny Guo