fs.watch fired twice when I change the watched file

后端 未结 12 1521
星月不相逢
星月不相逢 2020-12-09 01:30
 fs.watch( \'example.xml\', function ( curr, prev ) {
   // on file change we can read the new xml
   fs.readFile( \'example.xml\',\'utf8\', function ( err, data ) {         


        
12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 02:24

    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.

提交回复
热议问题