Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning a value to shell script from a node.js file

Tags:

shell

node.js

I am calling a NodeJS file like this in a shell script:

$ node process.js
$ let "errors |= $?"

I want to see if the process.js file returned any errors. How do I return a value inside process.js file so that I can capture it in my shell script.

like image 480
user2002640 Avatar asked Oct 22 '25 10:10

user2002640


1 Answers

You can set the exitCode (and let the node process die naturally):

process.exitCode = 1 

Or you can force-kill it:

process.exit(1)

in both cases it will return 1 as the exit code.

https://nodejs.org/api/process.html#process_process_exit_code

like image 185
laggingreflex Avatar answered Oct 23 '25 23:10

laggingreflex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!