Gary Sieling

Node error: ‘..’ is not recognized as an internal or external command [fixed]

If you try to execute commands in Node, you can get weird errors like this:

'..' is not recognized as an internal or external command, 
operable program or batch file.

Apparently Node doesn’t exactly shell this out the way you’d expect. Here is an example of something that would generate this error:

exec(
  '../script.sh', 
  (error: any, stdout: any, stderr: any) => { 
    ..
  }
);

Rather than referencing the full path to the script, you can set the “cwd” parameter in the “options” argument to exec:

exec(
  'script.sh', 
  {cwd: '../data'},
  (error: any, stdout: any, stderr: any) => { 
    ..
  }
);
Exit mobile version