Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

435
Visualizações
HTML onClick node js function loading 'require' another module in the onClick function not working

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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

 const button = document.getElementById('btn');
 const demo = document.getElementById('demo');
    
    button.onclick = function() {
        demo.innerHTML = 'Hello World';
    };
    
    <button id="btn" >Click me</button>
    <p id="demo"> </p>
    

If you want to load a module you need to show some of your node.js code as we don't see what that looks like and what you want to render.

I suggest reading the documentation of Node.js and EJS.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda