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

185
Visualizações
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 à 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