'File stay in my folder after deleting but deleted after restart Node JS
I have a function that loops over an array that contains paths to files, then I delete each of them. The files are uploaded with Multer in a folder "assets/temp/" Here is my delete method using fs :
exports.unlinkFiles = (filesPathsArr) => {
try {
filesPathsArr.forEach((filePath) => {
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath)
console.log('File deleted : ', filePath)
}
})
} catch (error) {
throw error
}
}
My input for example :
['assets\temp\pexelsphoto19886811645117462309.jpg', 'assets\temp\relaxtriptest1645118333937.mp3']
My output :
File Deleted : assets\temp\pexelsphoto19886811645117462309.jpg
File Deleted : assets\temp\relaxtriptest1645118333937.mp3
But in my folder temp :
+ And if I try to open the file, it say 'Enable to read..'
+ When I restart the server, the file just disapear
Is this just a local problem with my machine, maybe the problem will go away in production? Or maybe it's just a small detail that I shouldn't worry about? Or is it something else ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

