noProcessExit (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noProcessExit - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
no-process-exit - Same as
n/no-process-exit - Inspired from
unicorn/no-process-exit
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noProcessExit": "error" } } }}Description
Section titled “Description”Disallow the use of process.exit().
In Node.js, process.exit() stops the program right away.
Work that is still in progress, such as writing a file, sending a network request, or waiting on a timer, never finishes.
The program may also stop without printing why, which makes the problem hard to find.
Throw an error instead.
An error that nothing catches also stops the program, and Node.js prints its message and where it happened.
To choose the exit code (the number the program reports when it ends, where 0 means success),
set process.exitCode and let the program finish on its own.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”if (somethingBadHappened) { console.error("Something bad happened!"); process.exit(1);}code-block.js:3:5 lint/nursery/noProcessExit ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Don't use process.exit().
1 │ if (somethingBadHappened) {
2 │ console.error("Something bad happened!");
> 3 │ process.exit(1);
│ ^^^^^^^^^^^^^^^
4 │ }
5 │
ℹ It stops the program right away, before work in progress finishes and without saying why it stopped.
ℹ Throw an error instead, or set process.exitCode to choose the exit code.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
if (somethingBadHappened) { throw new Error("Something bad happened!");}
if (somethingElseHappened) { console.error("Something else happened!"); process.exitCode = 1;}See Also
Section titled “See Also”- If you want to require importing
processfromnode:processinstead of using the global, seenoProcessGlobal. - If you want to disallow reading
process.env, seenoProcessEnv.
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.