title: How do I wait for multiple fs.readFile calls?
body: <p>My objective is to read data from two files and compare the data. My input files are result3.json and result4.json.The data in these files are coma separated.</p>
  
  <p>result3.json</p>
  
  <pre><code>[
    "temp1.txt",
    "temp2.txt",
  ]
  </code></pre>
  
  <p>node:</p>
  
  <pre><code>function readFromFile(file) {
      var fileNames = [];
      //setTimeout(function() {
          fs.readFile(file,function(err, data){
              if (err) {
                  return console.log(err);
              }
              var temp = JSON.parse(data.toString().split(","));
              // console.log(temp.length);
              for (let index = 0; index &lt; temp.length; index++) {
                  //console.log(temp[index]);
                  fileNames.push(temp[index]);
                  //console.log(fileNames[index]);
              }
              Done(); // to block the async call
          });
          //},3000);
      //console.log(fileNames.length);
      return fileNames;
  }
  
  var baseListOfFiles = readFromFile('./output/result3.json'); // Assume this is the base file
  var currentListOfFiles = readFromFile('./output/result4.json'); // Assume this is the current file
  
  function Done(){
      //console.log('Out baseListOfFiles + ' + baseListOfFiles.length);
      for (let index = 0; index &lt; baseListOfFiles.length; index++) {
          console.log("[baseListOfFiles] " + baseListOfFiles[index]);
      }
  
      //console.log('Out currentListOfFiles+ ' + currentListOfFiles.length);
      for (let index = 0; index &lt; currentListOfFiles.length; index++) {
          console.log("[currentListOfFiles] " + currentListOfFiles[index]);
      }
  
  }
  </code></pre>
  
  <p>Above is my code. It seems to be async call, so it always return 0 fileNames.
  Is there any way to control it?</p>