Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 1.04 KB

cleanup.md

File metadata and controls

36 lines (26 loc) · 1.04 KB

Cleanup plugin

Features

  • The cleanup plugin is an event emitted when the process is exiting
  • Execute functions just before the process exits
  • ⚠️ Functions can't be asynchronous

Example

const sh = require('kool-shell')

// Caught exit events and automatically logs errors
sh.caughtExits(true)

function cleanupAction(code) {
  if (code === 0) console.log('App is exiting without an error, cool!')
}

// Add a new function to call when exiting
sh.on('cleanup', cleanupAction)

// Remove cleanupAction from the functions to call when exiting
sh.removeListener('cleanup', cleanupAction)

Usage

sh.caughtExits([log])

This tells kool-shell to handle SIGINT and uncaughtException events.

  • log (String, default true): Automatically log errors. If set to false, the errors will not be displayed.

sh.on('cleanup', cleanupAction)

Kool-shell emits cleanup when your script exits and will immediately call cleanupAction


[More infos about event emitters in Nodejs](https://nodejs.org/api/events.html)