title: Run JS function on Node server after OnClick event in HTML
body: <p>I am using <strong>node.js</strong> on <strong>Windows</strong>, with <strong>express</strong> module to generate a static page that has a Submit form which I want to run an <code>update()</code> function on the Server (i.e. not expose my js file publicly) when someone clicks "Submit" button.</p>
  
  <p><strong>PROBLEM:</strong></p>
  
  <p>It seems my <code>update()</code> function fails to be recognized from the HTML. The following error is generated:</p>
  
  <blockquote>
    <p>Uncaught ReferenceError: update is not defined
        at HTMLInputElement.onclick ((index):23)</p>
  </blockquote>
  
  <p>I suspect this is the result of my node project not being set up correctly.</p>
  
  <hr>
  
  <p><strong>Server file (server.js):</strong></p>
  
  <pre><code>var fs = require('fs');
  var express = require("express");
  var app     = express();
  
  app.get('/',function(req,res){
    res.sendFile(path.join(__dirname+'/index.html'));
    //__dirname : It will resolve to your project folder.
  });
  
  //loading all files in public folder
  //see instructions in https://expressjs.com/en/starter/static-files.html
  app.use(express.static('public'));
  
  app.listen(8080);
  
  console.log("Running at Port 8080");
  </code></pre>
  
  <p><strong>HTML file (index.html):</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;body&gt;
  
  &lt;div id="div1"&gt;
    &lt;p id="p1"&gt;This is a static paragraph.&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;p&gt;
    &lt;script type="text/javascript" src="start.js"&gt;&lt;/script&gt;
  &lt;/p&gt;
  
  Input:
  &lt;br&gt;
  &lt;input type="text" name="human_input" value=""&gt;
  &lt;br&gt;
  &lt;input type="button" value="Submit" onclick="update()"&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>JS file (compute.js)</strong></p>
  
  <pre><code>function update() {
      console.log("this is running!")
  }
  </code></pre>
  
  <p><em>^^ note, this is a sample script I am trying to get working.</em></p>
  
  <p><strong>My folder structure</strong></p>
  
  <pre><code>/
  - node_modules
  -- *
  - public
  -- start.js
  - index.html
  - compute.js
  - package-lock.json
  - server.js
  - start.js
  </code></pre>
  
  <p><strong>Notes:</strong></p>
  
  <ul>
  <li>calling <code>update()</code> from <code>onclick</code> worked previously when I was not using node.</li>
  </ul>