title: Fetch request returns html/text instead of JSON content when launched from Nodejs server
body: <p>I am launching a html webpage in my NodeJS server. On running the <code>server.js</code> file, it basically writes json data to a file, then launches the Nodejs server after 3 seconds  (so the HTML file has enough time to fetch the written data) as shown below.</p>
  <pre><code>setTimeout(() =&gt; {
    const server = http.createServer((req, res) =&gt; {
      res.writeHead(200, { &quot;content-type&quot;: &quot;text/html&quot; });
      fs.createReadStream(&quot;index.html&quot;).pipe(res);
    });
    server.listen(3000);
    console.log(`Server is running on http://localhost:3000/`);
  }, 3000);
  </code></pre>
  <p>But, when I fetch the <code>sites.json</code> file, the content received is HTML code in the network tab.</p>
  <pre><code>    &lt;script&gt;
          fetch('sites.json')
              .then(function (response) {
                  return response.json();
              })
              .then(function (data) {
                  appendData(data);
                  console.log(data)
              })
              .catch(function (err) {
                  console.log('error: ' + err);
              });
          function appendData(data) {
              var mainContainer = document.getElementById(&quot;myData&quot;);
              for (var i = 0; i &lt; data.length; i++) {
                  var div = document.createElement(&quot;div&quot;);
                  div.innerHTML = 'Name: ' + data[i];
                  mainContainer.appendChild(div);
              }
          }
      &lt;/script&gt;
  </code></pre>
  <p>I tried to make http request and it worked, therefore the problem only occurs when I try to fetch json files locally.</p>
  <p>I am not sure if this is the proper way to host a http server since it's my first time attempting this.</p>