I have code like:
<!DOCTYPE html>
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onclick Event</h2>
<p>The onclick event triggers a function when an element is clicked on.</p>
<p>Click to trigger a function that will output "Hello World":</p>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script>
function myFunction() {
const os = require('os')
let hostName = os.hostname()
alert(hostName);
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
</body>
</html>
The code works when I remove:
const os = require('os')
hostName = os.hostname()
alert(hostName);
I however need to load a module in this function that is being used for the onClick event.
Please note that I am a noob to javascript. Any and all assistance / guidance will be much appreciated.
Thanks.
UPDATE:
for those coming to this page, check: Node-style require for in-browser javascript?