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.
Examples
Section titled “Examples”process.exit(0);
process.exit(1);
if (error) { process.exit(1);}
function exitHandler() { process.exit(1);}throw new Error("Application failed");
function main() { return 1;}
async function run() { throw new Error("Fatal error");}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
n/no-process-exitunicorn/no-process-exit - Oxlint:
unicorn/no-process-exit