Using Nodejs and image-downloader. I am trying to run a compiler function at the end after all the images have downloaded. The imageDownload function gets triggered multiple times. The console.log(‘Saved to’, filename); runs way after everything.
import {image} from ‘image-downloader’;
await imageDownload (‘https://syntheticnews.com/wp-content/uploads/2023/12/Kodiak_Defense_1-1024×683.jpg’);
export async function imageDownload (url) {
var options={
url: url,
dest: `../../testimage.jpg`,
};
image(options)
.then(({ filename }) => {
console.log('Saved to', filename);
})
.catch((err) => console.error(err));
}
console.log ("This will be the next function and should run after the save to filename log");
The await on the function call just seems to await the running of the code not the downloading of the file. I really need an await on the .then statement but that doesn’t work :). Is there a better way than watching the folder and await the files expected?