title: Reading a file in real-time using Node.js
body: <p>I need to work out the best way to read data that is being written to a file, using node.js, in real time. Trouble is, Node is a fast moving ship which makes finding the best method for addressing a problem difficult.</p>
  
  <p><strong>What I Want To Do</strong><br/>
  I have a java process that is doing something and then writing the results of this thing it does to a text file. It typically takes anything from 5 mins to 5 hours to run, with data being written the whole time, and can get up to some fairly hefty throughput rates (circa. 1000 lines/sec).</p>
  
  <p>I would like to read this file, in real time, and then, using node aggregate the data and write it to a socket where it can be graphed on the client.</p>
  
  <p>The client, graphs, sockets and aggregation logic are all done but I am confused about the best approach for reading the file.</p>
  
  <p><strong>What I Have Tried (or at least played with)</strong><br/>
  <code>FIFO</code> - I can tell my Java process to write to a fifo and read this using node, this is in fact how we have this currently implemted using Perl, but because everything else is running in node it makes sense to port the code over.</p>
  
  <p><code>Unix Sockets</code> - As above.</p>
  
  <p><code>fs.watchFile</code> - will this work for what we need? </p>
  
  <p><code>fs.createReadStream</code> - is this better than watchFile?</p>
  
  <p><code>fs</code> &amp; <code>tail -f</code> - seems like a hack.</p>
  
  <p><strong>What, actually, is my Question</strong><br/>
  I am tending towards using Unix Sockets, this seems the fastest option. But does node have better built-in features for reading files from the fs in real time?</p>