title: Send data from node.js to frontend using pure js
body: <p>I am trying to send an object with data from a Node.js server to js file (for using this data in frontend).</p>
  
  <p>In the file <strong>main.js</strong> I am manipulating the DOM. I do the following request:</p>
  
  <pre class="lang-js prettyprint-override"><code>let dataName = [];
  let request = async ('http://localhost:3000/') =&gt; {
      const response = await fetch(url);
      const data = await response.json();
      dataName = data.name;
  }
  
  let name = document.getElementById('name');
  name.textContent = dataName;
  </code></pre>
  
  <p>Then in the file <strong>server.js</strong> I have an object:</p>
  
  <pre class="lang-js prettyprint-override"><code>data = [
      {
          "id": 1,
          "name": "Jhon"
      },
      {
          "id": 2,
          "name": "Mike"
      }
  ];
  </code></pre>
  
  <p>And I would like to send it as json string (or another way) to <strong>main.js</strong> as response for my request.</p>
  
  <p><strong>Problem:</strong> My data is displayed on window in browser. How could I get it as response? </p>
  
  <p><strong>I tried</strong> </p>
  
  <pre class="lang-js prettyprint-override"><code>let express = require('express');
  let app = express();
  app.use(express.static(`main`));
  app.get('/', function(req, res){
      res.json(data); //also tried to do it through .send, but there data only on window in browser
  });
  app.listen(3000);
  </code></pre>
  
  <p>Could someone tell me what to change in my code or point me in the direction in which to google? (I don't want to use template engines).</p>
  
  <p>Help me pls :) Peace be with you.</p>