Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prestaul/on-exit
Register tasks to perform when the process exits
https://github.com/prestaul/on-exit
Last synced: 13 days ago
JSON representation
Register tasks to perform when the process exits
- Host: GitHub
- URL: https://github.com/prestaul/on-exit
- Owner: Prestaul
- License: mit
- Created: 2015-04-28T16:31:50.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-28T19:03:02.000Z (over 9 years ago)
- Last Synced: 2024-12-06T23:20:03.913Z (about 1 month ago)
- Language: JavaScript
- Size: 121 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# on-exit
Easily register tasks to perform when the current node process exits.
# Install
```bash
npm install on-exit
```## Usage
Call onExit one or more times to add process cleanup tasks:```js
var onExit = require('on-exit');onExit(function() {
console.log('Closing db connections...');
db.close();
});onExit(function() {
console.log('Performing other cleanup...');
app.cleanup();
});
```When the process exits handlers will be run in the order that they were added.
## Debug logs
You can set a logging function if you would like to log kill signals and exit events:```js
var onExit = require('on-exit').logger(function(msg) {
myCustomLogger.log(msg);
});// Or to console.log
onExit.logger(console.log.bind(console));
```