Skip to content

shahradelahi/node-exit-signal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

exit-signal

CI NPM Version MIT License Install Size

exit-signal is a Node.js utility for handling process termination gracefully. The process.on('exit') event does not capture every method by which a process can terminate. By registering custom exit handlers, you can ensure proper cleanup and effective resource management.


πŸ“¦ Installation

npm install exit-signal

πŸ“– Usage

import { gracefullyExit, onExit } from 'exit-signal';

// Example 1: Register a simple exit handler
const unsubscribe = onExit(() => {
  console.log('Process is exiting... Cleaning up resources.');
});

// Unsubscribe the handler
unsubscribe();

// Example 2: Register an exit handler for specific signals
onExit(async (exitCode) => {
  console.log(`Received ${exitCode}. Performing async cleanup...`);
  await new Promise((resolve) => setTimeout(resolve, 1000));
  console.log('Cleanup completed.');
});

// Example 3: Trigger a graceful exit manually
gracefullyExit();

πŸ“š Documentation

For all configuration options, please see the API docs.

🀝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub

Thanks again for your support, it is much appreciated! πŸ™

License

MIT Β© Shahrad Elahi and contributors.

About

πŸ›‘ Gracefully handle process termination in Node.js with custom exit hooks.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published