Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

437
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda