title: How can I extract (read + delete) from a textfile in NodeJS?
body: <p>I'm building a script that reads log files, handles what needs to be handled then writes them to a database</p>
  <h3>Some caveats :</h3>
  <p>Some log files have a lot of input, multiple times a second
  Some log files have few to no input at all</p>
  <h3>What I try in simple words:</h3>
  <p>Reading the first line of a file, then deleting this line to go to the next one, while I handle the first line, other lines could be added..</p>
  <h3>Issues I'm facing</h3>
  <ol>
  <li>When I try reading a file then processing it, then deleting the
  files, some lines have been added</li>
  <li>When the app crashes while
  handling multiple lines at once for any reason, I can't know what
  lines have been processed.</li>
  </ol>
  <h3>Tried so far</h3>
  <pre><code>fs.readdir('logs/', (err, filenames) =&gt; {
  filenames.forEach((filename) =&gt; {
    fs.readFile('logs/'+filename, 'utf-8', (err, content) =&gt; {
      
      //processing all new lines (can take multiple ms)
  
      //deleting file
      fs.unlink('logs/'+filename)
    });
  });
  </code></pre>
  <p>});</p>
  <p>Is there not a (native or not) method to 'take' first line(s), or take all lines, from a file at once?</p>
  <p>Something similar to what the Array.shift() method does to arrays..</p>