1.2.2 • Published 5 years ago

node-exit v1.2.2

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
5 years ago

Node-Exit

npm version

A simple process exit hook to make sure you can run your clean up code before node process exits.

Code Example

The application uses pm2 to manage processes. When user presses CTRL+C to kill application, the signal will be sent to child processes as well. pm2 will try to recover these processes. With this module, we can tell pm2 no longer monit terminated processes.

In app.js

const shutdown = require('node-exit')

shutdown.registerExitHandler((isExpectedExit, error) => {
  if (!isExpectedExit) {
    console.fatal('Unexpected exit', error)
  }
  // Put your clean up code here
})

If you have more than one exit handling, here is an example:

const shutdown = require('node-exit')
const pm2 = require('pm2')

// Start PM2
const detached = false
pm2.connect(detached)

// Hook for stop
shutdown.on('will-exit', (isExpectedExit) => {
  console.debug('Will exit soon...')
  pm2.killDaemon()
})
1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago