On this page

    The exit code. For string type, only integer strings (e.g.,'1') are allowed. Default: undefined.

    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