title: Send a response from the serve-side to client-side (Node.js, javascript)
body: <p>Based on the following structure below, I want to send my response (simple array [&quot;Tom&quot;, &quot;Bob&quot;, &quot;Sam&quot;])  from the server.js to index.js  Is it possible?</p>
  <p><strong>server.js</strong></p>
  <pre><code>app.get(&quot;/*&quot;, (req, res) =&gt; {
      res.sendFile(path.resolve(__dirname, &quot;frontend&quot;, &quot;index.html&quot;));
  });
  
  app.post('/settings', function(req, res, next){
  res.status(200).json({
                  ok: true,
                  data: [&quot;Tom&quot;, &quot;Bob&quot;, &quot;Sam&quot;]
              }); 
  });
  
  app.listen(process.env.PORT || 3000);
  </code></pre>
  <p><strong>frontend/index.html</strong></p>
  <pre><code>    &lt;nav class=&quot;nav&quot;&gt;
          &lt;a href=&quot;/&quot;&gt;Dashboard&lt;/a&gt;
          &lt;a href=&quot;/settings&quot;&gt;Settings&lt;/a&gt;
      &lt;/nav&gt;
      &lt;div id=&quot;app&quot;&gt;&lt;/div&gt;
      &lt;script type=&quot;module&quot; src=&quot;/static/js/index.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p><strong>/frontend/static/js/index.js</strong></p>
  <pre><code>document.querySelector(&quot;#app&quot;).innerHTML = await view.getHtml(); // load page.html
  //console.log(data);
  </code></pre>
  <p><strong>/frontend/static/html/page.html</strong></p>
  <pre><code>        &lt;button id=&quot;btn&quot;&gt;Save&lt;/button&gt;
         &lt;script&gt;
       
     var btn = document.getElementById(&quot;btn&quot;);
  btn.addEventListener(&quot;click&quot;, function() {
  
    fetch('/settings', {
      method: 'POST', 
             headers: {
              &quot;Content-Type&quot;: &quot;text/plain&quot;
          },
      body: JSON.stringify(anotherData), 
      headers: {
        'Content-Type': 'application/json'
      }
    }).then(response =&gt; response.json())
      .then(function(response) {
          if (response.ok) {
              console.log('got data: ', response.data);
          }
      }).catch(function(error) {
          console.log(error);
      });
    
  
  }, false);
     &lt;/script&gt;
  </code></pre>