fs.watch( \'example.xml\', function ( curr, prev ) {
// on file change we can read the new xml
fs.readFile( \'example.xml\',\'utf8\', function ( err, data ) {
I was downloading file with puppeteer and once a file saved, I was sending automatic emails. Due to problem above, I noticed, I was sending 2 emails. I solved by stopping my application using process.exit() and auto-start with pm2. Using flags in code didn't saved me.
If anyone has this problem in future, one can use this solution as well. Exit from program and restart with monitor tools automatically.