Child process

subprocess.exitCode

Records the normal exit status after completion, or null when no normal exit code is available. A signal termination is distinct. Tested on Node.js 22.16.0. Example output (one line per entry): ["true", "5"].

Formal Syntax & Structure

nodejs syntaxnodejs
subprocess.exitCode

Return Value

number | null

Exit status.

Working Example

Example Snippetnodejs
import { spawn } from 'node:child_process';import { once } from 'node:events';const c = spawn(process.execPath, ['-e', 'process.exitCode=5'], { env: {}, stdio: 'ignore' });console.log(c.exitCode === null);await once(c, 'close');console.log(c.exitCode);
Node.js Reference