I've been trying to perform an asynchronous operation before my process is terminated.
Saying 'terminated' I mean every possibility of termination:
ctrl+c
- Uncaught exception
- Crashes
- End of code
- Anything..
To my knowledge the exit
event does that but for synchronous operations.
Reading the Nodejs docs i found the beforeExit
event is for the async operations BUT :
The 'beforeExit' event is not emitted for conditions causing explicit termination, such as calling
process.exit()
or uncaught exceptions.The 'beforeExit' should not be used as an alternative to the 'exit' event unless the intention is to schedule additional work.
Any suggestions?
require('child_process').exec('node afterExit.js');
, it's just a thought though – Boswallexec('node afterExit.js some_param some_other_param');
and access then withprocess.args
or alternatively create a json file with required data and pass path to that file to your script and load that file from afterExit.js – Boswallchild_process
exec, spawn. fork methods, would really apreaciate if you could take a look at this question i have just posted #41210401 – Constituent