exit hook is is called when there is no event in event loop anymore or manually we call process.exit()
exit hook only supports synchronous task inside it because there is no access to event loop anymore inside it
Even though, beforeExit supports async tasks, based on node document
The 'beforeExit' event is not emitted for conditions causing explicit
termination, such as calling process.exit() or uncaught exceptions
So you have no access to event loop anymore, what you’re gonna do? IF it’s just a log , then the simplest solution might be calling another child process which has access to an event loop
const childProcess = require('child_process');
process.on('exit', () => {
childProcess.exec('node ./what-to-do-asynchronously.js');
});