suman
suman copied to clipboard
check if file is executable
https://github.com/kevva/executable/blob/master/index.js
const fs = require('fs');
console.log(process.argv);
fs.open(__filename, 'r+', function(err, fd){
if(err) throw err;
const b = Buffer.alloc(4);
fs.read(fd, b, 0, 4, 0, function(err, bytesRead, buffer){
if(err) throw err;
console.log('data: ', bytesRead);
console.log('buffer: ', String(buffer));
});
});
or we can potentially use:
const fs = require('fs');
fs.access('./foobar.sh', fs.constants.X_OK, (err) => {
console.log(err ? 'cannot execute' : 'can execute');
});