delete file in Node.js
var fs = require('fs');
const url = '/media/uploads/' + uniqueFileName;
fs.access(url, fs.F_OK, async (err, ac) => {
if (err) {
return res.status(500).send({
message: "Error",
statusCode: 500
});
} else {
await fs.unlink(url, (ferr, fc) => {
if (ferr) {
console.log('Error Occure On File Deletion!');
return res.status(500).send({
message: "Error",
statusCode: 500
});
} else {
// saveDuplicatedUser();
console.log('File deleted!');
return res.status(200).send({
message: "Error",
statusCode: 200
});
}
});
}
});