P
process.exitCode
History
Added in: v0.11.8
v0.11.8
Introduced in: v0.10.0
v0.10.0
Only accepts a code of type number, or of type string if it represents an integer.
v20.0.0
A number which will be the process exit code, when the process either
exits gracefully, or is exited via process.exit() without specifying
a code.
The value of process.exitCode can be updated by either assigning a value to
process.exitCode or by passing an argument to process.exit():
$ node -e 'process.exitCode = 9'; echo $? 9 $ node -e 'process.exit(42)'; echo $? 42 $ node -e 'process.exitCode = 9; process.exit(42)'; echo $? 42
The value can also be set implicitly by Node.js when unrecoverable errors occur (e.g. such as the encountering of an unsettled top-level await). However explicit manipulations of the exit code always take precedence over implicit ones:
$ node --input-type=module -e 'await new Promise(() => {})'; echo $? 13 $ node --input-type=module -e 'process.exitCode = 9; await new Promise(() => {})'; echo $? 9