Socket
Socket
Sign inDemoInstall

signal-exit

Package Overview
Dependencies
0
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    signal-exit

when you want to fire an event no matter how a process exits.


Version published
Weekly downloads
74M
decreased by-0.06%
Maintainers
2
Install size
10.5 kB
Created
Weekly downloads
 

Package description

What is signal-exit?

The signal-exit package is used to capture and handle events that indicate Node.js process is about to exit. This includes handling of signals like SIGINT and SIGTERM, as well as normal process termination. It allows developers to register callbacks that can perform cleanup or other final actions before the process exits.

What are signal-exit's main functionalities?

Capture exit events

This feature allows you to capture any kind of exit, whether it's due to a signal or a normal exit. The callback function is called with the exit code and the signal that caused the exit, if applicable.

const onExit = require('signal-exit');

const removeExitHandler = onExit(function (code, signal) {
  console.log('Process is exiting with code:', code, 'and signal:', signal);
});

// Later, if you decide you do not want to handle the exit:
removeExitHandler();

Unregister exit handler

This feature allows you to unregister a previously registered exit handler. This is useful if the exit handling logic is no longer needed, or if you want to replace it with a different handler.

const onExit = require('signal-exit');

const removeExitHandler = onExit(function () {
  // cleanup logic here
});

// When you no longer need to handle exits:
removeExitHandler();

Other packages similar to signal-exit

Readme

Source

signal-exit

Build Status Coverage NPM version Standard Version

When you want to fire an event no matter how a process exits:

  • reaching the end of execution.
  • explicitly having process.exit(code) called.
  • having process.kill(pid, sig) called.
  • receiving a fatal signal from outside the process

Use signal-exit.

var onExit = require('signal-exit')

onExit(function (code, signal) {
  console.log('process exited!')
})

API

var remove = onExit(function (code, signal) {}, options)

The return value of the function is a function that will remove the handler.

Note that the function only fires for signals if the signal would cause the process to exit. That is, there are no other listeners, and it is a fatal signal.

Options

  • alwaysLast: Run this handler after any other signal or exit handlers. This causes process.emit to be monkeypatched.

Keywords

FAQs

Last updated on 03 Feb 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc