I'm working with this code to delete some images using an array with the URL. It works fine, however when I want to return another array with the deleting status of each one, I get an empty array.
import fs from 'fs';
import path from 'path';
const pathStatic = path.join(__dirname, "../..", "public");
export const deleteImages = (images) => {
return images.map ((image) => {
fs.unlink(path.join(pathStatic, image), (err) => {
if (err) {
return {
status: 'error',
msg: 'The image could not be deleted.',
url: image
};
}
else{
return {
status: 'success',
msg: 'The image was deleted successfully.',
url: image
};
}
});
});
}
Not so sure what could be the issue.