title: How to await fs.readFile?
body: <p>I'm having problems with awaiting <code>fs.readFile()</code>
  I have a file where I want to iterate over each line, and save non-duplicated inside of an array <code>domains</code>.</p>
  <p>However, when I call my function with <code>fs.readFile</code> and after it I call <code>console.log(domains)</code> domains is empty.</p>
  <p>Code</p>
  <pre class="lang-js prettyprint-override"><code>var fs = require(&quot;fs&quot;);
  var re = /@(.*?):/;
  let domains = [];
  
  const parseProviders = () =&gt; {
      fs.readFile(&quot;file.txt&quot;, (error, data) =&gt; {
      if (error) throw error;
      data
        .toString()
        .split(&quot;\n&quot;)
        .forEach((line, index, arr) =&gt; {
          try {
            line = line.match(re)[1];
            if(!domains.includes(line)) {
              domains.push(line);
            }
          } catch (err) {
            throw err;  
          }
        });
        console.log(domains); // this would work and print an array with non-duplicate items
    });
  }
  
  (() =&gt; {
    parseProviders();
    console.log(domains); // prints an empty array []
  })();
  </code></pre>