0

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!

0 Answers0