title: How to read the content of files synchronously in Node.js?
body: <p>This is what I have:</p>
  
  <pre><code>#! /usr/bin/env node
  
  var fs = require('fs'),
      files = fs.readdirSync(__dirname + '/files/'),
  
  files.forEach(function(file) {
    fs.readFile(__dirname + '/files/' + file, 'utf8', function (error, data) {
      console.log(data)
    })
  })
  </code></pre>
  
  <p>Even though I'm using <code>readdirSync</code> the output is still asynchronous:</p>
  
  <pre><code>alex@alex-K43U:~/node/readFiles$ node index.js 
  foo 1
  
  foo 3
  
  foo 2
  </code></pre>
  
  <p>How to modify the code so the output becomes synchronous?</p>
  
  <pre><code>alex@alex-K43U:~/node/readFiles$ node index.js 
  foo 1
  
  foo 2
  
  foo 3
  </code></pre>