1

I want to watch a specific file to look for specific changes using Node and also fetch those changes in the file. Is there anyway doing that using fs?

The Bassman
  • 2,241
  • 5
  • 26
  • 38
  • possible duplicate of [Observe file changes with node.js](http://stackoverflow.com/questions/13698043/observe-file-changes-with-node-js) – James Jul 23 '15 at 09:32

1 Answers1

1

Yes, you can do it by using fs.

How to do it:

  1. Load file content
  2. Watch file
  3. Compare content with the previous one when change event is triggered
  4. Update file content

It should look like this:

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

See:

Erazihel
  • 7,295
  • 6
  • 30
  • 53