Home > other >  How to check if nodejs process failed due to a timeout?
How to check if nodejs process failed due to a timeout?

Time:01-30

I spawn a synchronous process like this:

child = spawnSync('somecommand', { stdio: 'inherit', cwd: someDir, timeout: 30000});

Is there a reliable way to check if the child process failed due to the timeout option or some other error?

CodePudding user response:

You should check for the log of node which is running down there somewhere. You must be running this with a cli so you can see the log there. Or you can look for where the log is saved. Everything, specially the errors are noted there.

CodePudding user response:

If anyone runs into the same problem, there is a simple way to retrieve the timeout error code at run-time:

 if (child.error && child.error.code === "ETIMEDOUT") {
   console.log("child timed out");
 }
  •  Tags:  
  • Related