1

I have created a Node.js script which pick up some images from a directory and do the work and after doing all the process it moves the image to another folder and my script ends but did not exist, so when I add new images in the folder, I need to close the script first and rerun the script so that it will again pick up image and do the work.

fs.readdirSync(Imagefolder).forEach((file) => {
   ImagesNames.push("public/" + file);
});
ImagesNames.forEach((element) => {
 //do something
 });

after this as there is no image code won't run and sit idea, but I am thinking if there is any change in the direcotry it should re run this code.

How will I automate this so that whenever a change in folder/directory automatically node.js script rerun again

  • 2
    You'll need a watcher library, e.g. [chokidar](https://github.com/paulmillr/chokidar). – AKX Sep 08 '22 at 11:54

0 Answers0