0

I'm trying to make a system in which when I close my node.js program, it'll save the last id checked in the program to a text file

require('shutdown-handler').on('exit', function(e) {
   e.preventDefault();
   fs.writeFileSync('LastID.txt', "Change something in the text file");
});

Right now the text inside the text file is "TEST" and in the code you see above I'm trying to change it to "Change something in the text file" when ever I close the node.js program. For some reason I can't get it to change. I'm pretty bad at javascript and I'm not sure how to fix or even make this work. Any help or tips would be lovely.

Kurokku
  • 3
  • 3
  • Shutdown how exactly? All this thing is doing is listening for a Ctrl+C or `SIGINT` and then calling the handler function. The `e.preventDefault()` is actually there to stop the process from terminating. – Neil Lunn Jun 10 '18 at 03:10
  • https://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits – The Alpha Jun 10 '18 at 03:13

0 Answers0