【问题标题】:Event handler on file change and get changes in file using NodeJS File System文件更改事件处理程序并使用 NodeJS 文件系统获取文件更改
【发布时间】:2015-07-23 18:13:10
【问题描述】:

我想查看特定文件以使用 Node 查找特定更改并获取文件中的这些更改。有没有使用 fs 的方法?

【问题讨论】:

标签: node.js fs


【解决方案1】:

是的,您可以使用 fs 来做到这一点。

怎么做:

  1. 加载文件内容
  2. 观看文件
  3. change 事件触发时将内容与上一个比较
  4. 更新文件内容

应该是这样的:

fs.watch('foo', function (event, filename) {
  if (event == 'change') {
    // Load file content
    // Compare to one previously loaded
    // actualContent = newContent
  }
});

见:

【讨论】:

    猜你喜欢
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多