4

Example:

I have

var r = new FileReader();
    r.onload = function(e) {
        drawGraph(r.result);
    }
    r.readAsText(f);

drawing a graph from the file f input by the user.

Is there a way to check to see if the file f has been changed and then re load it's content without needing for the user to pick the file again?

1 Answers1

3

Yes, this can be achieved using Node.js's filesystem API which provides a "watch" function

NodeJS Filesystem API docs: https://nodejs.org/api/fs.html

Similar question: Observe file changes with node.js

fs.watch('somedir', function (event, filename) {
    console.log('event is: ' + event);
    if (filename) {
        console.log('filename provided: ' + filename);
    } else {
        console.log('filename not provided');
    }
});
Community
  • 1
  • 1
Jeff Voss
  • 3,637
  • 8
  • 46
  • 71