# n/no-process-exit

> Disallow `process.exit()`

`process.exit()` stops the process immediately. Output that hasn't been written yet is lost, `finally` blocks don't run, and the code that called yours doesn't get a chance to handle the problem or clean up.

Throw an error instead. If nothing catches it, the process ends with a stack trace and a failing exit code. To end with a specific exit code, set `process.exitCode` and let the process finish by itself.

{/* 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]
"n/no-process-exit" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad */}
```js
if (!config.valid) {
  console.error("invalid config");
  process.exit(1);
}
```

Not reported:

{/* good */}
```js
if (!config.valid) {
  throw new Error("invalid config");
}
```

{/* good */}
```js
if (!config.valid) {
  console.error("invalid config");
  process.exitCode = 1;
}
```

## When not to use it

A command line tool's entry file is a reasonable place for `process.exit()`, for example to stop while timers or sockets are still open.
