'How to interact with back-end script via a button

I have a very simple node.js setup:

demo1.html:

<html>
  <body>
    <button id="hello">My Button</button>
    <p>My paragraph</p>
  </body>
</html>

myfirst.js:

var http = require('http');
var fs = require('fs');
http.createServer(async function (req, res) {
  fs.readFile('demofile1.html', async function(err, data) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(data);
    return res.end();
  });

}).listen(8080);

In basic html, I can either call the function by putting onclick="" or .addEventListener. However, the function that I wanted to call contains secrets and of course, I don't want the client see it via source code/inspect.

May I know how can a button interact with the backend script WITHOUT onclick and accessible script files. The script should ONLY be in the backend script, i.e. myfirst.js?

Edit: I tried putting .addEventListener in myfirst.js and there is a reference error: document is not defined



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source