Skip to content

processExits

Prevent direct use of process.exit() for better error handling and testing.

✅ This rule is included in the node logical preset.

Calling process.exit() immediately terminates the Node.js process without allowing proper cleanup or error handling. This makes code harder to test and can lead to resource leaks or incomplete operations. Throwing errors provides better stack traces and allows proper error handling, while returning exit codes from CLI entry points maintains testability.

process.exit(0);
process.exit(1);
if (error) {
process.exit(1);
}
function exitHandler() {
process.exit(1);
}

This rule is not configurable.

If you are working with very specific Node.js system-level code that genuinely requires immediate process termination without cleanup, you might choose not to enable this rule. However, such cases are rare, and most applications benefit from proper error handling.

Alternately, if your application is not very large and/or doesn’t intend to live for a long time, proper process flow logic might not be worth it for you to implement. In that case this rule might not be for you.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.