# seppukujs

> do something before pkill

Latest version **1.0.1** (published 2022-06-25) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-06-25 |
| First published | 2022-06-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | geekhunger |
| Maintainers | geekhunger |
| Keywords | pkill, kill, process, nodejs, sig, sigterm, siginit, expressjs, nodejs |

## Links

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

## Recent versions

- 1.0.1 (latest) — 2022-06-25
- 1.0.0 — 2022-06-25

## README

# Readme

This module allows you to queue up tasks, that will be run in sequence, just before your application quits. You can use this to close alive database connections, stop active cronjobs or clean-up the memory before the process gets killed.

However, you should not use async function calls or put off application termination, because your application is about to kill itself anyways. Perform mandatory tasks and be okay with it.^^

Why yet another one? Because I've tried a ton of them on NPM and none worked for my clustered PM2 setup.

## How-To

```js
const die = require("seppukujs")

// register an event handler that will be fired once the current process is closed/killed
// function call returns a pointer to unregister that event handler again (most of the time you won't need that)
const stop_saying_goodbye = die(console.log.bind(undefined, "goodbye world"))

// unregister the event handler from the queue of signal listeners so that it won't be fired on close/kill of the process
stop_saying_goodbye()

die(function() {
    // do whatever you want inside this function...
    console.warn("did something :)")
})

die(() => {
    // same as above, but with arrow-function syntax...
})

// calling die() without any arguments will return a function to clear the entire queue of already registered event handlers!
const clear_entire_queue = die()
clear_entire_queue()

// same as above, but with shorthand syntax
die()()
```

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