# euthanasia

> Gracefully exits a Node.js process when memory or CPU usage exceeds defined thresholds. Supports customizable exit logic via async hooks.

Latest version **2.0.1** (published 2025-12-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install euthanasia
pnpm add euthanasia
yarn add euthanasia
bun add euthanasia
```

## Health

**Score 55/100 (C)** — status: stable.

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

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2025-12-18 |
| First published | 2023-07-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jacek Pietal |
| Maintainers | jacekpietal, pietal.dev |
| Keywords | nodejs, memory, cpu, resource-monitoring, graceful-exit, graceful-shutdown, oom, out-of-memory, high-cpu, self-terminate, process-exit, resource-limits, watchdog |

## Links

- npm: https://www.npmjs.com/package/euthanasia
- Repository: https://github.com/nenjack/euthanasia
- Homepage: https://github.com/nenjack/euthanasia#readme
- Issues: https://github.com/nenjack/euthanasia/issues
- npm.io page: https://npm.io/package/euthanasia

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2025-12-18
- 2.0.0 — 2025-06-04
- 1.4.0 — 2024-08-20
- 1.3.0 — 2023-07-02
- 1.2.0 — 2023-07-01
- 1.1.0 — 2023-07-01
- 1.0.0 — 2023-07-01

## README

# euthanasia

when your node.js process uses too much memory or cpu, allow it to gracefully exit

## usage:

```js
const euthanasia = require('euthanasia');

euthanasia({
  memory: 100, // 100 MB limit
  cpu: 80, // 80% CPU limit
  interval: 10000, // check every 10 seconds
  // called when either memory or CPU limit is exceeded
  ready: async ({ memory, cpu }) => {
    // your logic here
    if (memory) {
      console.log(`Memory limit exceeded: ${memory} MB`);
    }
    if (cpu) {
      console.log(`CPU limit exceeded: ${cpu.toFixed(2)}%`);
    }
    // You can return false to skip exit (e.g., wait for cleanup)
    return true;
  }
});
```

## install:

```bash
npm i euthanasia --save
```

## license:

MIT

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