title: How to use drain event of stream.Writable in Node.js
body: <p>In Node.js I'm using the <code>fs.createWriteStream</code> method to append data to a local file. In the Node documentation they mention the <code>drain</code> event when using <code>fs.createWriteStream</code>, but I don't understand it.</p>
  
  <pre><code>var stream = fs.createWriteStream('fileName.txt');
  var result = stream.write(data);
  </code></pre>
  
  <p>In the code above, how can I use the drain event? Is the event used properly below?</p>
  
  <pre><code>var data = 'this is my data';
  if (!streamExists) {
    var stream = fs.createWriteStream('fileName.txt');
  }
  
  var result = stream.write(data);
  if (!result) {
    stream.once('drain', function() {
      stream.write(data);
    });
  }
  </code></pre>