Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including on-exit with all npm packages installed. Try it out:

var onExit = require("on-exit")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

on-exit v1.0.1

Register tasks to perform when the process exits.


Easily register tasks to perform when the current node process exits.


npm install on-exit


Call onExit one or more times to add process cleanup tasks:

var onExit = require('on-exit');

onExit(function() {
    console.log('Closing db connections...');

onExit(function() {
    console.log('Performing other 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:

var onExit = require('on-exit').logger(function(msg) {

// Or to console.log


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free