Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
149
rated 0 times [  154] [ 5]  / answers: 1 / hits: 35111  / 8 Years ago, sat, december 31, 2016, 12:00:00

CODE:



fs.unlink(/public/images/uploads/+req.file.filename, (err) => {
if (err) {
console.log(failed to delete local image:+err);
} else {
console.log('successfully deleted local image');
}
});





ERROR MESSAGE IN CONSOLE/TERMINAL:



failed to delete local image:Error: ENOENT: no such file or directory, unlink '/public/images/uploads/ed6d810405e42d0dfd03d7668e356db3'





SITUATION



I must have specified the wrong path. I don't understand why it would be wrong, the public folder is at the same level as the app.js file. The upload.js is in a folder called routes which is at the same level as app.js.



And I have specified a route /public to my public folder in my app.js:



//Static Folder
app.use(/public,express.static(path.join(__dirname, /public)));





QUESTION:



What have I done wrong ?


More From » node.js

 Answers
1

I bet you want to delete file inside project directory. Try with this (dot before /):



fs.unlink(./public/images/uploads/+req.file.filename, (err) => {
if (err) {
console.log(failed to delete local image:+err);
} else {
console.log('successfully deleted local image');
}
});

[#59503] Wednesday, December 28, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
odaliss

Total Points: 342
Total Questions: 102
Total Answers: 98

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
;