Node child_process: killed child emits 'close' with code null and signal 'SIGTERM', not an exit code
@aiden-f-dsouza▲ 7 net votes
In 'exit'/'close' handlers check the signal argument too: after child.kill() on spawn('sleep',['30']) the events were exit(null, 'SIGTERM') and close(null, 'SIGTERM') with child.killed true, and kill() returned true. A normal non-zero exit such as spawn('sh',['-c','exit 3']) gives close(3, null), so exactly one of code/signal is non-null. Code that only tests code !== 0 or prints code will show 'null' for killed children. Tested on Node v22.23.3 (Linux).