title: Node.js server Browser rendering html file as text - All content types correct
body: <p>I am using a node.js file to start a server but my browser just renders the html as text.</p>
  <ul>
  <li>The html file has the .html extension.</li>
  <li>I have added all the necessary
  Content-Type headers</li>
  </ul>
  <p>At my whits end any help will be appreciated. Thanks in advance!</p>
  <p><strong>File Structure</strong></p>
  <pre><code>03_Feeds-Speed        
  ├─ scripts            
  │  ├─ FeedsSpeeds.js  
  │  ├─ main.js         
  │  └─ Page.js         
  ├─ styles             
  │  └─ style.css       
  ├─ index.html         
  ├─ README.md          
  └─ server.js          
  
  </code></pre>
  <p><strong>index.html</strong></p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
    &lt;title&gt;Feeds &amp; Speeds&lt;/title&gt;
    &lt;link href=&quot;styles/style.css&quot; rel=&quot;stylesheet&quot;&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;nav&quot; class=&quot;navbar&quot;&gt;
      &lt;nav&gt;
        &lt;h2&gt;Navigation&lt;/h2&gt;
        &lt;div id=&quot;FeedSpeed_button&quot;&gt;
          &lt;p&gt;Feeds &amp; Speeds&lt;/p&gt;
        &lt;div id=&quot;Material_button&quot;&gt;
          &lt;p&gt;Materials&lt;/p&gt;
          &lt;P&gt;Tool Library&lt;/P&gt;
        &lt;/div&gt;
      &lt;/nav&gt;
    &lt;/div&gt;
    &lt;div id=&quot;content&quot; class=&quot;content&quot;&gt;
      &lt;input type=&quot;button&quot; id=&quot;but&quot; value=&quot;click me&quot;&gt;
    &lt;/div&gt;
  
    &lt;script type=&quot;module&quot; src=&quot;scripts/main.js&quot;&gt;&lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p><strong>server.js</strong></p>
  <pre><code>let http = require('http');
  let fs = require('fs');
  
  
  
  http.createServer(function (req, res){
      fs.readFile('index.html', 'utf-8', function (err, data) {
  
          if (err){
              res.writeHead(404);
              res.write(&quot;problem!&quot;)
          } else {
  
              res.writeHead(200, {
                  'Content-Type' : 'text/html',
                  'Content-Type' : 'text/css',
                  'Content-Type' : 'application/javascript'
              }, charset='UTF-8');
  
          res.write(data);
          return res.end();
  
          }});
  }).listen(7800);
  
  </code></pre>