2

I am using shelljs module to execute a bash file in node for a server side program. I even tried child-process module to execute the bash file. In both cases I got permission denied error. I am using linux(ubuntu disto). Here is the code snippet.

var shell = require("shelljs");
var cp = require("child_process");
shell.exec('../scripts/test.sh');
cp.exec('../scripts/test.sh', (error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
if (error !== null) {
   console.log(`exec error: ${error}`);
 }
});

Here is the file structure.

 |-Parent file
   |-routes
     --file containing the above javascript code
   |-scripts
     --test.sh

Here is the error.

/bin/sh: 1: ../scripts/test.sh: Permission denied
/bin/sh: 1: ../scripts/test.sh: Permission denied
 exec error: Error: Command failed: ../scripts/test.sh
/bin/sh: 1: ../scripts/test.sh: Permission denied

Can anyone suggest me why this error is occurring and how to resolve it?
Note- I have not used any sudo commands in the test.sh . Just a simple echo command like echo "Hello World"

Fleabag
  • 21
  • 2

1 Answers1

2

You need to run chmod +x ../scripts/test.sh to give access to run the script file. If that fails, try to use Sudo to run the node script.