title: Periodically log the content of a file using setInterval and FileReader
body: <p>I'm attaching this f-tion to an <code>&lt;input type="file"&gt;</code> element as an "onclick" handler:</p>
  
  <pre><code>handleWatch(event) {
  
    event.preventDefault();
    const file = event.target.files[0];
    if (!file) {
      return;
    }
  
    const reader = new FileReader();
  
    setInterval(() =&gt; {
  
      reader.onload = async function(e) {
        const content = e.target.result;
  
        const lines = content.split('\n').filter((line) =&gt; {
          return !line.beginsWith('#') &amp;&amp; !(line === "");
        });
        const nLines = lines.length - 1;
  
        console.log("number of lines in file: " + nLines);
  
      }
      reader.readAsText(file, 'UTF-8');
  
    }, 1500);
  
  }
  </code></pre>
  
  <p>The idea is to create a logger which periodically checks the content of file (selected by user) for changes and persists to DB (this code removed for clarity). Interval execution works (logs to console), up to a point when the content is indeed changed, then none of the instructions inside reader.onload are executed.</p>