title: Writing large files with Node.js
body: <p>I'm writing a large file with node.js using a <a href="http://nodejs.org/docs/latest/api/streams.html#writable_Stream" rel="noreferrer">writable stream</a>:</p>
  
  <pre><code>var fs     = require('fs');
  var stream = fs.createWriteStream('someFile.txt', { flags : 'w' });
  
  var lines;
  while (lines = getLines()) {
      for (var i = 0; i &lt; lines.length; i++) {
          stream.write( lines[i] );
      }
  }
  </code></pre>
  
  <p>I'm wondering if this scheme is safe without using <a href="http://nodejs.org/docs/latest/api/streams.html#event_drain_" rel="noreferrer"><code>drain</code></a> event? If it is not (which I think is the case), what is the pattern for writing an arbitrary large data to a file?</p>