title: How do I use `fs.readFile` to read an HTML file in Node.js?
body: <p>I have used <code>fs.readFileSync()</code> to read HTML files and it's working. But I have a problem when I use <code>fs.readFile()</code>. May you please help me to resolve the problem? Any help will be appreciated!</p>
  
  <ul>
  <li>Using <code>fs.readFileSync()</code>:</li>
  </ul>
  
  <pre class="lang-js prettyprint-override"><code>const http = require("http");
  const fs = require("fs");
  
  http.createServer((req, res) =&gt; {
    res.writeHead(200, {
      "Content-type": "text/html"
    });
  
    const html = fs.readFileSync(__dirname + "/bai55.html", "utf8");
    const user = "Node JS";
  
    html = html.replace("{ user }", user);
    res.end(html);
  }).listen(1337, "127.0.0.1");
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/X44q3.png" alt="Using &lt;code&gt;fs.readFileSync&lt;/code&gt;"></p>
  
  <ul>
  <li>Using <code>fs.readFile()</code>. Why can't it read HTML files?</li>
  </ul>
  
  <pre class="lang-js prettyprint-override"><code>const http = require("http");
  const fs = require("fs");
  
  http.createServer((req, res) =&gt; {
    res.writeHead(200, {
      "Content-type": "text/html"
    });
  
    const html = fs.readFile(__dirname + "/bai55.html", "utf8");
    const user = "Node JS";
  
    html = html.replace("{ user }", user);
    res.end(html);
  }).listen(1337, "127.0.0.1");
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/5SEf9.png" alt="Using &lt;code&gt;fs.readFile()&lt;/code&gt;"></p>