{"_id":"async-exit-hook","_rev":"94939","name":"async-exit-hook","description":"Run some code when the process exits (supports async hooks and pm2 clustering)","dist-tags":{"latest":"2.0.1"},"maintainers":[{"name":"tapppi","email":"moilanen.tapani@gmail.com"}],"time":{"modified":"2021-06-03T10:31:38.000Z","created":"2016-03-12T15:30:43.478Z","2.0.1":"2017-08-03T10:23:51.952Z","2.0.0":"2017-08-03T10:14:48.389Z","1.1.2":"2017-03-29T15:49:34.186Z","1.1.1":"2016-11-04T06:28:24.743Z","1.1.0":"2016-10-13T10:32:54.099Z","1.0.2":"2016-03-12T16:02:06.377Z","1.0.1":"2016-03-12T15:30:43.478Z"},"users":{"ys_sidson_aidson":true,"mechanicalhuman":true,"touskar":true,"simonepri":true,"temasm":true},"author":{"name":"Tapani Moilanen","email":"moilanen.tapani@gmail.com","url":"https://github.com/tapppi"},"repository":{"type":"git","url":"git+https://github.com/tapppi/async-exit-hook.git"},"versions":{"2.0.1":{"name":"async-exit-hook","version":"2.0.1","description":"Run some code when the process exits (supports async hooks and pm2 clustering)","license":"MIT","repository":{"type":"git","url":"git+https://github.com/tapppi/async-exit-hook.git"},"author":{"name":"Tapani Moilanen","email":"moilanen.tapani@gmail.com","url":"https://github.com/tapppi"},"contributors":[{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"}],"engines":{"node":">=0.12.0"},"scripts":{"test":"xo && nyc ava","release":"standard-version"},"files":["index.js"],"keywords":["exit","quit","process","hook","graceful","handler","shutdown","sigterm","sigint","sighup","pm2","cluster","child","reload","async","terminate","kill","stop","event"],"devDependencies":{"ava":"^0.21.0","coveralls":"^2.11.14","nyc":"^10.3.2","standard-version":"^4.2.0","xo":"^0.18.2"},"ava":{"files":["test/*.js","!tests/cases/*"]},"gitHead":"0ef56bc594f6b0f382007e00c3721a7921a29a9f","bugs":{"url":"https://github.com/tapppi/async-exit-hook/issues"},"homepage":"https://github.com/tapppi/async-exit-hook#readme","_id":"async-exit-hook@2.0.1","_npmVersion":"5.3.0","_nodeVersion":"6.11.2","_npmUser":{"name":"tapppi","email":"moilanen.tapani@gmail.com"},"dist":{"shasum":"8bd8b024b0ec9b1c01cccb9af9db29bd717dfaf3","size":4662,"noattachment":false,"key":"/async-exit-hook/-/async-exit-hook-2.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-exit-hook/download/async-exit-hook-2.0.1.tgz"},"maintainers":[{"name":"tapppi","email":"moilanen.tapani@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-exit-hook-2.0.1.tgz_1501755830965_0.9513590028509498"},"directories":{},"publish_time":1501755831952,"_cnpm_publish_time":1501755831952,"_hasShrinkwrap":false},"2.0.0":{"name":"async-exit-hook","version":"2.0.0","description":"Run some code when the process exits (supports async hooks and pm2 clustering)","license":"MIT","repository":{"type":"git","url":"git+https://github.com/tapppi/async-exit-hook.git"},"author":{"name":"Tapani Moilanen","email":"moilanen.tapani@gmail.com","url":"https://github.com/tapppi"},"contributors":[{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"}],"engines":{"node":">=0.12.0"},"scripts":{"test":"xo && nyc ava","release":"standard-version"},"files":["index.js"],"keywords":["exit","quit","process","hook","graceful","handler","shutdown","sigterm","sigint","sighup","pm2","cluster","child","reload","async","terminate","kill","stop","event"],"devDependencies":{"ava":"^0.21.0","coveralls":"^2.11.14","nyc":"^10.3.2","standard-version":"^4.2.0","xo":"^0.18.2"},"ava":{"files":["test/*.js","!tests/cases/*"]},"gitHead":"2472fc25a7fa8434b6eef498b4a36319dc3029ab","bugs":{"url":"https://github.com/tapppi/async-exit-hook/issues"},"homepage":"https://github.com/tapppi/async-exit-hook#readme","_id":"async-exit-hook@2.0.0","_npmVersion":"5.3.0","_nodeVersion":"6.11.2","_npmUser":{"name":"tapppi","email":"moilanen.tapani@gmail.com"},"dist":{"shasum":"9bf60a5f1aaa618def24539128730276c765d27f","size":4638,"noattachment":false,"key":"/async-exit-hook/-/async-exit-hook-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-exit-hook/download/async-exit-hook-2.0.0.tgz"},"maintainers":[{"name":"tapppi","email":"moilanen.tapani@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/async-exit-hook-2.0.0.tgz_1501755287490_0.6174647635780275"},"directories":{},"publish_time":1501755288389,"_hasShrinkwrap":false,"_cnpm_publish_time":1501755288389},"1.1.2":{"name":"async-exit-hook","version":"1.1.2","description":"Run some code when the process exits (supports async hooks and pm2 clustering)","license":"MIT","repository":{"type":"git","url":"git+https://github.com/tapppi/async-exit-hook.git"},"author":{"name":"Tapani Moilanen","email":"moilanen.tapani@gmail.com","url":"https://github.com/tapppi"},"contributors":[{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"}],"engines":{"node":">=0.12.0"},"scripts":{"test":"xo && nyc ava","release":"standard-version"},"files":["index.js"],"keywords":["exit","quit","process","hook","graceful","handler","shutdown","sigterm","sigint","sighup","pm2","cluster","child","reload","async","terminate","kill","stop","event"],"devDependencies":{"ava":"^0.16.0","coveralls":"^2.11.14","nyc":"^8.3.1","standard-version":"^3.0.0","xo":"^0.16.0"},"ava":{"files":["test/*.js","!tests/cases/*"]},"gitHead":"6bc834b26bcd5e1f262c21442d9b7b543735b637","bugs":{"url":"https://github.com/tapppi/async-exit-hook/issues"},"homepage":"https://github.com/tapppi/async-exit-hook#readme","_id":"async-exit-hook@1.1.2","_shasum":"8095d75e488c29acee0551fe87252169d789cfba","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.9.4","_npmUser":{"name":"tapppi","email":"moilanen.tapani@gmail.com"},"dist":{"shasum":"8095d75e488c29acee0551fe87252169d789cfba","size":4491,"noattachment":false,"key":"/async-exit-hook/-/async-exit-hook-1.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-exit-hook/download/async-exit-hook-1.1.2.tgz"},"maintainers":[{"name":"tapppi","email":"moilanen.tapani@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/async-exit-hook-1.1.2.tgz_1490802572221_0.8973375633358955"},"directories":{},"publish_time":1490802574186,"_hasShrinkwrap":false,"_cnpm_publish_time":1490802574186},"1.1.1":{"name":"async-exit-hook","version":"1.1.1","description":"Run some code when the process exits (supports async hooks and pm2 clustering)","license":"MIT","repository":{"type":"git","url":"git+https://github.com/tapppi/async-exit-hook.git"},"author":{"name":"Tapani Moilanen","email":"moilanen.tapani@gmail.com","url":"https://github.com/tapppi"},"contributors":[{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"}],"engines":{"node":">=0.12.0"},"scripts":{"test":"xo && nyc ava","release":"standard-version"},"files":["index.js"],"keywords":["exit","quit","process","hook","graceful","handler","shutdown","sigterm","sigint","sighup","pm2","cluster","child","reload","async","terminate","kill","stop","event"],"devDependencies":{"ava":"^0.16.0","coveralls":"^2.11.14","nyc":"^8.3.1","standard-version":"^3.0.0","xo":"^0.16.0"},"ava":{"files":["test/*.js","!tests/cases/*"]},"gitHead":"e3951164dfe0061dda5e319c0e0f2eddd297a922","bugs":{"url":"https://github.com/tapppi/async-exit-hook/issues"},"homepage":"https://github.com/tapppi/async-exit-hook#readme","_id":"async-exit-hook@1.1.1","_shasum":"363e1603d2aa448483e842f423061804f08ba35a","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"tapppi","email":"moilanen.tapani@gmail.com"},"dist":{"shasum":"363e1603d2aa448483e842f423061804f08ba35a","size":4398,"noattachment":false,"key":"/async-exit-hook/-/async-exit-hook-1.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-exit-hook/download/async-exit-hook-1.1.1.tgz"},"maintainers":[{"name":"tapppi","email":"moilanen.tapani@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/async-exit-hook-1.1.1.tgz_1478240904192_0.1678797248750925"},"directories":{},"publish_time":1478240904743,"_cnpm_publish_time":1478240904743,"_hasShrinkwrap":false},"1.1.0":{"name":"async-exit-hook","version":"1.1.0","description":"Run some code when the process exits (supports async hooks and pm2 clustering)","license":"MIT","repository":{"type":"git","url":"git+https://github.com/tapppi/async-exit-hook.git"},"author":{"name":"Tapani Moilanen","email":"moilanen.tapani@gmail.com","url":"https://github.com/tapppi"},"contributors":[{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"}],"engines":{"node":">=0.12.0"},"scripts":{"test":"xo && nyc ava","release":"standard-version"},"files":["index.js"],"keywords":["exit","quit","process","hook","graceful","handler","shutdown","sigterm","sigint","sighup","pm2","cluster","child","reload","async","terminate","kill","stop","event"],"devDependencies":{"ava":"^0.16.0","coveralls":"^2.11.14","nyc":"^8.3.1","standard-version":"^3.0.0","xo":"^0.16.0"},"ava":{"files":["test/*.js","!tests/cases/*"]},"gitHead":"802173a8a9063f08f67c34df21f08a50dd642975","bugs":{"url":"https://github.com/tapppi/async-exit-hook/issues"},"homepage":"https://github.com/tapppi/async-exit-hook#readme","_id":"async-exit-hook@1.1.0","_shasum":"e7ab3b4f5ca942664161b0642d39485d95cfdc77","_from":".","_npmVersion":"3.10.6","_nodeVersion":"4.4.7","_npmUser":{"name":"tapppi","email":"moilanen.tapani@gmail.com"},"dist":{"shasum":"e7ab3b4f5ca942664161b0642d39485d95cfdc77","size":4271,"noattachment":false,"key":"/async-exit-hook/-/async-exit-hook-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-exit-hook/download/async-exit-hook-1.1.0.tgz"},"maintainers":[{"name":"tapppi","email":"moilanen.tapani@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/async-exit-hook-1.1.0.tgz_1476354772307_0.989501457195729"},"directories":{},"publish_time":1476354774099,"_cnpm_publish_time":1476354774099,"_hasShrinkwrap":false},"1.0.2":{"name":"async-exit-hook","version":"1.0.2","description":"Run some code when the process exits (supports async hooks andpm2 clustering)","license":"MIT","repository":{"type":"git","url":"git+https://github.com/tapppi/async-exit-hook.git"},"author":{"name":"Tapani Moilanen","email":"moilanen.tapani@gmail.com","url":"https://github.com/tapppi"},"contributors":[{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"}],"engines":{"node":">=0.12.0"},"scripts":{"test":"nyc ava"},"files":["index.js"],"keywords":["exit","quit","process","hook","graceful","handler","shutdown","sigterm","sigint","sighup","pm2","cluster","child","reload","async","terminate","kill","stop","event"],"devDependencies":{"ava":"0.13.0","coveralls":"^2.11.8","nyc":"^6.0.0"},"ava":{"files":["test/*.js","!tests/cases/*"]},"gitHead":"1eb042e519df9905aa6a71ff1728f6994d0541b9","bugs":{"url":"https://github.com/tapppi/async-exit-hook/issues"},"homepage":"https://github.com/tapppi/async-exit-hook#readme","_id":"async-exit-hook@1.0.2","_shasum":"c3bd72a3d39e446482469f9a90ad3963c783c955","_from":".","_npmVersion":"3.6.0","_nodeVersion":"4.2.2","_npmUser":{"name":"tapppi","email":"moilanen.tapani@gmail.com"},"dist":{"shasum":"c3bd72a3d39e446482469f9a90ad3963c783c955","size":3979,"noattachment":false,"key":"/async-exit-hook/-/async-exit-hook-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-exit-hook/download/async-exit-hook-1.0.2.tgz"},"maintainers":[{"name":"tapppi","email":"moilanen.tapani@gmail.com"}],"_npmOperationalInternal":{"host":"packages-13-west.internal.npmjs.com","tmp":"tmp/async-exit-hook-1.0.2.tgz_1457798524159_0.8370754467323422"},"directories":{},"publish_time":1457798526377,"_cnpm_publish_time":1457798526377,"_hasShrinkwrap":false},"1.0.1":{"name":"async-exit-hook","version":"1.0.1","description":"Run some code when the process exits (supports async hooks andpm2 clustering)","license":"MIT","repository":{"type":"git","url":"git+https://github.com/tapppi/async-exit-hook.git"},"author":{"name":"Tapani Moilanen","email":"moilanen.tapani@gmail.com","url":"https://github.com/tapppi"},"contributors":[{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"http://sindresorhus.com"}],"engines":{"node":">=0.12.0"},"scripts":{"test":"nyc ava"},"files":["index.js"],"keywords":["exit","quit","process","hook","graceful","handler","shutdown","sigterm","sigint","sighup","pm2","cluster","child","reload","async","terminate","kill","stop","event"],"devDependencies":{"ava":"0.13.0","coveralls":"^2.11.8","nyc":"^6.0.0"},"ava":{"files":["test/*.js","!tests/cases/*"]},"gitHead":"90497785b3912aa033d359d440d2c74807cf74cb","bugs":{"url":"https://github.com/tapppi/async-exit-hook/issues"},"homepage":"https://github.com/tapppi/async-exit-hook#readme","_id":"async-exit-hook@1.0.1","_shasum":"774f775ed893b578d39bab3d4b14619d91f62d55","_from":".","_npmVersion":"3.6.0","_nodeVersion":"4.2.2","_npmUser":{"name":"tapppi","email":"moilanen.tapani@gmail.com"},"dist":{"shasum":"774f775ed893b578d39bab3d4b14619d91f62d55","size":3845,"noattachment":false,"key":"/async-exit-hook/-/async-exit-hook-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/async-exit-hook/download/async-exit-hook-1.0.1.tgz"},"maintainers":[{"name":"tapppi","email":"moilanen.tapani@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/async-exit-hook-1.0.1.tgz_1457796641009_0.6231779009103775"},"directories":{},"publish_time":1457796643478,"_cnpm_publish_time":1457796643478,"_hasShrinkwrap":false}},"readme":"# async-exit-hook\n[![Build Status](https://api.travis-ci.org/Tapppi/async-exit-hook.svg)](https://travis-ci.org/Tapppi/async-exit-hook)\n[![Coverage Status](https://coveralls.io/repos/github/Tapppi/async-exit-hook/badge.svg?branch=master)](https://coveralls.io/github/Tapppi/async-exit-hook?branch=master)\n\n> Run some code when the process exits\n\nThe `process.on('exit')` event doesn't catch all the ways a process can exit. This module catches:\n\n* process SIGINT, SIGTERM and SIGHUP, SIGBREAK signals  \n* process beforeExit and exit events  \n* PM2 clustering process shutdown message ([PM2 graceful reload](http://pm2.keymetrics.io/docs/usage/cluster-mode/#graceful-reload))  \n\nUseful for cleaning up. You can also include async handlers, and add custom events to hook and exit on.\n\nForked and pretty much rewritten from [exit-hook](https://npmjs.com/package/exit-hook).\n\n\n## Install\n\n```\n$ npm install --save async-exit-hook\n```\n\n## Usage\n\n### Considerations and warning\n#### On `process.exit()` and asynchronous code\n**If you use asynchronous exit hooks, DO NOT use `process.exit()` to exit.\nThe `exit` event DOES NOT support asynchronous code.**\n>['beforeExit' is not emitted for conditions causing explicit termination, such as process.exit()]\n(https://nodejs.org/api/process.html#process_event_beforeexit)\n\n#### Windows and `process.kill(signal)`\nOn windows `process.kill(signal)` immediately kills the process, and does not fire signal events, \nand as such, cannot be used to gracefully exit. See *Clustering and child processes* for a\nworkaround when killing child processes. I'm planning to support gracefully exiting \nwith async support on windows soon.\n\n### Clustering and child processes\nIf you use custom clustering / child processes, you can gracefully shutdown your child process\nby sending a shutdown message (`childProc.send('shutdown')`).\n\n### Example\n```js\nconst exitHook = require('async-exit-hook');\n\nexitHook(() => {\n    console.log('exiting');\n});\n\n// you can add multiple hooks, even across files\nexitHook(() => {\n    console.log('exiting 2');\n});\n\n// you can add async hooks by accepting a callback\nexitHook(callback => {\n    setTimeout(() => {\n        console.log('exiting 3');\n        callback();\n    }, 1000);\n});\n\n// You can hook uncaught errors with uncaughtExceptionHandler(), consequently adding \n// async support to uncaught errors (normally uncaught errors result in a synchronous exit).\nexitHook.uncaughtExceptionHandler(err => {\n    console.error(err);\n});\n\n// You can hook unhandled rejections with unhandledRejectionHandler()\nexitHook.unhandledRejectionHandler(err => {\n    console.error(err);\n});\n\n// You can add multiple uncaught error handlers\n// Add the second parameter (callback) to indicate async hooks\nexitHook.uncaughtExceptionHandler((err, callback) => {\n    sendErrorToCloudOrWhatever(err) // Returns promise\n        .then(() => { \n             console.log('Sent err to cloud'); \n         });\n        .catch(sendError => {\n             console.error('Error sending to cloud: ', err.stack));\n        })\n        .then(() => callback);\n    });\n});\n\n// Add exit hooks for a signal or custom message:\n\n// Custom signal\n// Arguments are `signal, exitCode` (SIGBREAK is already handled, this is an example)\nexitHook.hookEvent('SIGBREAK', 21);\n\n// process event: `message` with a filter\n// filter gets all arguments passed to *handler*: `process.on(message, *handler*)`\n// Exits on process event `message` with msg `customShutdownMessage` only\nexitHook.hookEvent('message', 0, msg => msg !== 'customShutdownMessage');\n\n// All async hooks will work with uncaught errors when you have specified an uncaughtExceptionHandler\nthrow new Error('awesome');\n\n//=> // Sync uncaughtExcpetion hooks called and retun\n//=> '[Error: awesome]'\n//=> // Sync hooks called and retun\n//=> 'exiting'\n//=> 'exiting 2'\n//=> // Async uncaughtException hooks return\n//=> 'Sent error to cloud'\n//=> // Sync uncaughtException hooks return\n//=> 'exiting 3'\n```\n\n\n## License\n\nMIT © Tapani Moilanen  \nMIT © [Sindre Sorhus](http://sindresorhus.com)\n","_attachments":{},"homepage":"https://github.com/tapppi/async-exit-hook#readme","bugs":{"url":"https://github.com/tapppi/async-exit-hook/issues"},"license":"MIT"}