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

184
Vistas
Display Image whenever an update is detected using JavaScript

I'm currently working on a website that has an image file that is frequently overwritten, but since the website doesn't automatically update the image when it is changed, I'm trying to re-display the image whenever it senses a change in the file.

Currently, this is the part that displays the image:

<script>
    const fs = require('fs');
   function updateImage() {
            var image = document.getElementById("img");
            image.src = image.src.split("?")[0] + "?" + new Date().getTime();
    }
    fs.watch(document.getElementById("img"), function(eventType, filename) {
        if (event == 'change'){
            updateImage();
        }
    });
</script>

I know from testing that updateImage() works on it's own, but I was wondering why the fs.watch() isn't detecting when the image file gets overwritten. Also, does fs.watch() constantly check for updates or do I need to constantly loop to check for updates?

Thank you!

about 4 years ago · Juan Pablo Isaza
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