# unicorn/no-process-exit

> Disallow `process.exit()`

`process.exit()` stops the process immediately. Pending work is dropped, `finally` blocks don't run, and the code that called yours never gets a chance to handle the failure. Throw an error instead, or set `process.exitCode` and let the process end when it has nothing left to do.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/no-process-exit" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
function loadConfig(path) {
  if (!exists(path)) {
    console.error("config not found");
    process.exit(1);
  }
}
```

Not reported:

{/* good */}
```js
function loadConfig(path) {
  if (!exists(path)) {
    throw new Error("config not found");
  }
}
```

The rule allows `process.exit()` in three places. The first is a file that starts with `#!`. That's a command-line program, so it decides when to exit:

{/* good */}
```js
#!/usr/bin/env bun
if (!(await run())) {
  process.exit(1);
}
```

The second is a handler passed to `process.on()` or `process.once()`:

{/* good */}
```js
process.on("SIGINT", () => {
  closeServer();
  process.exit(130);
});
```

The third is a file that imports something from `node:worker_threads`, where `process.exit()` ends the worker thread, not the process:

{/* good */}
```js
import { parentPort } from "node:worker_threads";

parentPort.on("message", message => {
  if (message === "stop") process.exit(0);
});
```
