// as early in startup as possiblerequire('capture-exit').captureExit();// when you want to schedule some work on exit:function onExit() { return something.processWillExit(); // you can return promises, which will pause exit until fulfilled}require('capture-exit').onExit(onExit); // add an exit handlerrequire('capture-exit').offExit(onExit); // allows one to remove an exit handle if it is not longer required