title: Why do we need buffers in node.js?
body: <p>To display the contents of the file in browser using node, I first tried this:</p>
  
  <pre><code>var express = require('express')
    , fs  = require('fs')
    , app = express()
    , port = process.env.PORT || 5000;
  
  app.use(express.logger());
  
  var data = fs.readFileSync('index.html');
  
  
  app.get('/', function(req, res){
    res.send(data);
  });
  
  app.listen(port, function(){
    console.log('Listenting on ' + port);
  });
  </code></pre>
  
  <p>However, this didn't work as expected. Browser actually offered to contents of <code>index.html</code> as file that I first have to download &amp; then manually open that in text editor.  then, I tried using buffer to do the same thing:</p>
  
  <pre><code>var express = require('express')
    , fs  = require('fs')
    , app = express()
    , port = process.env.PORT || 5000;
  
  app.use(express.logger());
  
  var data = new Buffer(fs.readFileSync('index.html'));
  
  
  app.get('/', function(req, res){
    res.send(data.toString('utf-8'));
  });
  
  app.listen(port, function(){
    console.log('Listenting on ' + port);
  });
  </code></pre>
  
  <p>This works as expected &amp; contents of <code>index.html</code> were display inside the browser window. However, In My limited userstanding about Node.js. Buffer class is a global type for dealing with binary data. However the <code>index.html</code> file didn't contain any binary data.  so my questions are:</p>
  
  <ol>
  <li>In above code, why did the contents of <code>index.html</code> were offered as file download(without buffer) vs being displayed directly in browser(with buffer)?</li>
  <li>Why do I need to use buffer when the file contains only string data, no binary?</li>
  <li>What are the offer places where buffers are used?</li>
  <li>If I want to learn more about buffers &amp; there use in Node. where do I go?</li>
  </ol>