# exit-compat

> A replacement for process.exit that ensures stdio are fully drained before exiting

Latest version **1.0.5** (published 2026-05-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install exit-compat
pnpm add exit-compat
yarn add exit-compat
bun add exit-compat
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2026-05-26 |
| First published | 2025-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=0.8 |
| Dependencies | 0 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kevin Malakoff |
| Maintainers | kmalakoff |
| Keywords | exit, process, stdio, stdout, stderr, drain, flush |

## Links

- npm: https://www.npmjs.com/package/exit-compat
- Repository: https://github.com/kmalakoff/exit-compat
- Issues: https://github.com/kmalakoff/exit-compat/issues
- npm.io page: https://npm.io/package/exit-compat

## Recent versions

- 1.0.5 (latest) — 2026-05-26
- 1.0.4 — 2025-12-13
- 1.0.3 — 2025-12-12
- 1.0.2 — 2025-12-12
- 1.0.1 — 2025-12-12
- 1.0.0 — 2025-12-11

## README

## exit-compat

A replacement for `process.exit()` that ensures stdio streams are fully drained before exiting.

This is needed for Node 0.8-0.10 compatibility where `process.exit()` could truncate stdout/stderr output because streams hadn't finished flushing. Modern Node.js versions handle this automatically.

### Installation

```bash
npm install exit-compat
```

### Usage

```javascript
var exit = require('exit-compat');

console.log('This will be fully written before exit');
exit(0);
```

### API

#### exit(exitCode)

- `exitCode` (number): The exit code to pass to `process.exit()`

The function waits for `process.stdout` and `process.stderr` to drain before calling `process.exit()`.

### Why?

On Node 0.8-0.10, calling `process.exit()` immediately could truncate stdout/stderr output. This was fixed in Node 0.11.8+, but this package provides a consistent solution across all Node versions.

### Credits

Based on the [exit](https://github.com/cowboy/node-exit) package by "Cowboy" Ben Alman.

---
_Source: https://npm.io/package/exit-compat · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
