title: How can I use fs.read() in Node js
body: <p>I try to use Nodejs fs.read Method in Mac OS. However it doesn't work..
  I use below source code</p>
  
  <pre><code>    var fs = require('fs');
      fs.open('helloworld.txt', 'r', function(err, fd) {
          fs.fstat(fd, function(err, stats) {
  
              var bufferSize=stats.size  ,
                  chunkSize=512,
                  buffer=new Buffer(bufferSize),
                  bytesRead = 0;
  
              while (bytesRead &lt; bufferSize) {
                  if ((bytesRead + chunkSize) &gt; bufferSize) {
                      chunkSize = (bufferSize - bytesRead);
                  }
  
                  fs.read(fd, buffer, bytesRead, chunkSize, bytesRead, testCallback);
                  bytesRead += chunkSize;
              }
              console.log(buffer.toString('utf8'));
          });
          fs.close(fd);
      });
  
      var testCallback = function(err, bytesRead, buffer){
          console.log('err : ' +  err);
      };
  </code></pre>
  
  <p>Actually, I use some example in stackoverflow.</p>
  
  <p>When I execute the source,</p>
  
  <pre><code>err : Error: EBADF, read
  </code></pre>
  
  <p>this err is returned.</p>
  
  <p>However if I use readFile method, it works well.</p>
  
  <pre><code>    fs.readFile('helloworld.txt', function (err, data) {
         if (err) throw err;    
         console.log(data.toString('utf8'));
      });
  </code></pre>
  
  <p>result is</p>
  
  <pre><code>Hello World!
  </code></pre>
  
  <p>Of course, it's same file.</p>
  
  <p>Please, let me know what the problem is.</p>
  
  <p>Thank you.</p>