title: Node.js read file using async/await
body: <p>I am experimenting with async/await code to read file.
  Here's my code:</p>
  
  <pre><code>var fs = require('fs');
  
  function readFile(fileName) {
    return new Promise(resolve =&gt; {
      //console.log(test);
      fs.readFile(fileName, 'utf8', function (err, data) {
        if (err) throw err;
  
        console.log(fileName)
        console.log(data)
      })
      resolve();
    });
  }
  
  async function run() {
    await readFile('file1.txt');
    await readFile('file2.txt');
    readFile('file3.txt');
  }
  
  run();
  </code></pre>
  
  <p>But the result is still random. It means file3 sometime read before file2. Where am I doing wrong?</p>