title: Node.js wait for all files read in the loop
body: <p>I am new to the javascript/node.js event driven paradigm.</p>
  
  <p>I need to stop the for after forEach to make sure all files have been read and then I continue. How should I implement <code>wait_for_all_files_read()</code> in this context?</p>
  
  <pre><code>my_list.forEach(function(element) {
    fs.readFile(element.file_path, function(err, data)  {
      if(err) throw err;
      element.obj=JSON.parse(data);
    });
  });
  wait_for_all_files_read(); &lt;-----------
  analyze(my_list)
  </code></pre>
  
  <p>Neither solution <a href="https://medium.com/@nodejs_recipes/how-to-make-a-function-wait-until-a-callback-has-been-called-using-node-js-c29b36a8e02" rel="nofollow noreferrer">[1]</a> or <a href="https://stackoverflow.com/questions/5010288/how-to-make-a-function-wait-until-a-callback-has-been-called-using-node-js">[2]</a> work for me.</p>