title: Reading all files in a directory, store them in objects, and send the object
body: <p>I do not know if this is possible, but here goes. And working with callbacks makes it even more difficult.</p>
  
  <p>I have a directory with html files that I want to send back to the client in Object chunks with node.js and socket.io.</p>
  
  <p>All my files are in /tmpl</p>
  
  <p>So socket needs to read all the files in /tmpl.</p>
  
  <p>for each file it has to store the data in an object with the filename as the key, and the content as the value.</p>
  
  <pre><code>  var data;
    // this is wrong because it has to loop trough all files.
    fs.readFile(__dirname + '/tmpl/filename.html', 'utf8', function(err, html){
        if(err) throw err;
        //filename must be without .html at the end
        data['filename'] = html;
    });
    socket.emit('init', {data: data});
  </code></pre>
  
  <p>The final callback is also wrong. It has to be called when all the files in the directory are done.</p>
  
  <p>But I do not know how to create the code, anyone know if this is possibel?</p>