title: How to do `tail -f logfile.txt`-like processing in node.js?
body: <p><code>tail -f logfile.txt</code> outputs the last 10 lines of logfile.txt, and then continues to output appended data as the file grows.</p>
  
  <p>What's the recommended way of doing the <code>-f</code> part in node.js?</p>
  
  <p>The following outputs the entire file (ignoring the "show the last 10 lines") and then exits.</p>
  
  <pre><code>var fs = require('fs');
  var rs = fs.createReadStream('logfile.txt', { flags: 'r', encoding: 'utf8'});
  rs.on('data', function(data) {
    console.log(data);
  });
  </code></pre>
  
  <p>I understand the event-loop is exiting because after the stream end &amp; close event there are no more events -- I'm curious about the best way of continuing to monitor the stream.</p>