title: How to make GET request with express.js to a local json file?
body: <p>I want to make a GET request to a local JSON file with express.</p>
  
  <p>In my server.js I have this</p>
  
  <pre><code>var data = {};
  app.get('/src/assets/data.json', (req, res) =&gt; {
    console.log(res)
    res.writeHead(200, {
      'Content-type': 'application/json'
    });
  
    res.end(JSON.stringify(data));
  });
  </code></pre>
  
  <p>data.json looks like this</p>
  
  <pre><code>[{
      "param": "one",
      "param": "two",
      "param": "three"
    }]
  </code></pre>
  
  <p>Also I made a function for GET request which is called as soon as the DOM is loaded</p>
  
  <pre><code>getData() {
      let xhr = new XMLHttpRequest();
      xhr.open('GET', '/src/assets/data.json', true);
      xhr.onreadystatechange = () =&gt; {
        if (xhr.readyState === XMLHttpRequest.DONE &amp;&amp; xhr.status === 200) {
          console.log(xhr)
        }
      };
      xhr.send();
    }
  </code></pre>
  
  <p>I'm getting a response back but it is an empty object. I'm guessing it is because in my server file <code>var data = {};</code> is empty but I'm not sure what to do with it?</p>