Skip to content

process.exit(code) and process.exitCode coercion to integer #405

Description

@AugustinMauroy

Description

Since passing non-integer values to process.exit(code) and process.exitCode is deprecated (DEP0164) and has reached End-of-Life status in Node.js v20.0.0, we should provide a codemod to replace them.

  • The codemod should convert non-integer values passed to process.exit() to proper integers or remove them.
  • The codemod should convert non-integer values assigned to process.exitCode to proper integers or undefined.
  • The codemod should preserve undefined, null, integer numbers, and integer strings (e.g., '1').
  • The codemod should add explicit integer conversion for floating-point numbers or other numeric values.

Additional Information

Note that in Node.js v20.0.0, passing values other than undefined, null, integer numbers, and integer strings to process.exit() or assigning them to process.exitCode now throws an ERR_INVALID_ARG_TYPE error.

Exit codes should always be integers between 0-255, where 0 indicates success and non-zero indicates an error. The automatic coercion of non-integer values was removed because it could lead to unexpected behavior.

Examples

Example 1: Boolean value in process.exit()

Before:

process.exit(true);

After:

process.exit(1); // true coerced to 1

Example 2: Boolean false in process.exit()

Before:

process.exit(false);

After:

process.exit(0); // false coerced to 0

Example 3: Floating-point number in process.exit()

Before:

process.exit(1.5);

After:

process.exit(Math.floor(1.5)); // Explicitly convert to integer: 1

Example 4: Object assigned to process.exitCode

Before:

process.exitCode = { code: 1 };

After:

process.exitCode = 1; // Extract the integer value

Example 5: String (non-integer) in process.exit()

Before:

process.exit("error");

After:

process.exit(1); // Use appropriate error code

Example 6: Conditional with boolean

Before:

const hasError = true;
process.exit(hasError);

After:

const hasError = true;
process.exit(hasError ? 1 : 0);

Example 7: process.exitCode with boolean

Before:

const success = false;
process.exitCode = success;

After:

const success = false;
process.exitCode = success ? 0 : 1;

Example 8: Valid integer string (no change needed)

Before:

process.exit("1");

After:

process.exit("1"); // Integer strings are still valid

Example 9: Valid values (no change needed)

Before:

process.exit(0);
process.exit(1);
process.exit(undefined);
process.exit(null);
process.exitCode = 0;
process.exitCode = undefined;

After:

process.exit(0);
process.exit(1);
process.exit(undefined);
process.exit(null);
process.exitCode = 0;
process.exitCode = undefined;

Example 10: Arithmetic expression

Before:

process.exit(0.5 + 0.7); // Results in 1.2

After:

process.exit(Math.floor(0.5 + 0.7)); // Explicitly convert to integer: 1

Refs

Activity

  1. KevinSailema commented on Mar 29, 2026

    @KevinSailema

    Hello! I'd like to take this issue.

    I'll implement the codemod to handle the transformations for both process.exit and process.exitCode according to the rules described, and I'll make sure to cover the edge cases with tests.

    Could you assign it to me?

  2. AugustinMauroy commented on Mar 29, 2026

    @AugustinMauroy
    MemberAuthor

    we don't assign to issue just feel free to open a pr

  3. moved this from 🔖 Todo to 🏗 In progress in Userland Migrations Boardon May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions