I have the following delete function in expressjs but when I try use the path of the element I want to remove it appears as undefined yet I've revised the tutorial and still dont see where the problem is:
router.delete('/messagedelete/:empId', function (req, res) {
Message.remove({empId: req.params.empId}, function(err, message) {
console.log(message.path);
console.log("got inside");
if(err) {
return res.send({status: "200", response: "fail"});
}
console.log(message.path);
fs.unlink(message.path, function() {
res.send ({
status: "200",
responseType: "string",
response: "success"
});
});
});
});
I import fs like this at the top of the file:
const fs = require('fs');