Watch a folder for changes using node.js, and print file paths when they are changed

后端 未结 3 799
误落风尘
误落风尘 2020-11-30 18:33

I\'m trying to write a node.js script that watches for changes in a directory of files, and then prints the files that are changed. How can I modify this script so that it w

3条回答
  •  伪装坚强ぢ
    2020-11-30 19:04

    Why not just use the old fs.watch? Its pretty straightforward.

    fs.watch('/path/to/folder', (eventType, filename) => {
    console.log(eventType);
    // could be either 'rename' or 'change'. new file event and delete
    // also generally emit 'rename'
    console.log(filename);
    })
    

    For more info and details about the options param, see Node fs Docs

提交回复
热议问题