Skip to content

noProcessExit (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noProcessExit": "error"
}
}
}
}

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.

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;
}
  • If you want to require importing process from node:process instead of using the global, see noProcessGlobal.
  • If you want to disallow reading process.env, see noProcessEnv.