0.4.5 • Published 5 months ago

you-died v0.4.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

you-died

Decently exit your Node.js application when it is interrupted.

Motivation

I need to do an asynchronous cleanup action on exit, none of the modules worked for me:

  • exit-hook
  • async-exit-hook
  • death
  • node-cleanup

So I tried it myself, and finally found this:

process.once('uncaughtException', async () => {
  await cleanup()

  process.exit(0)
})

process.once('SIGINT', () => { throw new Error() })

Install

npm install --save you-died
# or
yarn add you-died

Usage

import youDied from 'you-died'
// or whatever name you feel is decent.

const cancel1 = youDied(async () => {
  await cleanup1()
})

const cancel2 = youDied(async () => {
  await cleanup2()
})

Under the hood

This module listens to these events:

  • uncaughtException
  • SIGINT
  • SIGTERM
  • SIGBREAK

Signal event handlers will throw an error named Signal, which is caught by the uncaughtException handler.

API

youDied

function youDied(cleanup: () => void | PromiseLike<void>): () => void

You can call this function multiple times, and the cleanup function will run sequentially.

0.4.5

5 months ago

0.4.4

10 months ago

0.4.3

1 year ago

0.4.2

2 years ago

0.4.1

2 years ago

0.3.0

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago