I have uploaded files into a temp directory using multer
const imageStorage = multer.diskStorage({
// Destination to store image
destination: 'images',
filename: (req, file, cb) => {
cb(null, file.fieldname + '_' + Date.now()
+ path.extname(file.originalname))
fs.writeFile("/tmp/"+file.originalname, message, function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
}
});
How can i remove it ?
>Solution :
You can delete the file using
fs.unlink(path, (err) => {
if (err) throw err //handle your error the way you want to;
console.log('path/file.txt was deleted');//or else the file will be deleted
});
);
Refernce : https://nodejs.org/api/fs.html