title: nodejs streams vs callbacks
body: <p>Im reading this article: <a href="http://elegantcode.com/2011/04/06/taking-baby-steps-with-node-js-pumping-data-between-streams/" rel="noreferrer">http://elegantcode.com/2011/04/06/taking-baby-steps-with-node-js-pumping-data-between-streams/</a> and having some slight troubles understanding streams.</p>
  
  <p><strong>Quote:</strong></p>
  
  <blockquote>
  <pre><code>"Suppose we want to develop a simple web application
  that reads a particular file from disk and send it to the browser.
  The following code shows a very simple and naïve implementation
  in order to make this happen."
  </code></pre>
  </blockquote>
  
  <p>So the code sample is as follows:</p>
  
  <pre><code>var readStream = fileSystem.createReadStream(filePath);
  readStream.on('data', function(data) {
      response.write(data);
  });
  
  readStream.on('end', function() {
      response.end();        
  });
  </code></pre>
  
  <p>Why would we use that above way when we could simply do:</p>
  
  <pre><code>fs.readFile(filePath, function(err, data){
    response.write(data);
    response.end();
  });
  </code></pre>
  
  <p>When or why would I use streams?</p>