Following is my code in update method for an event -
Event.findOneAndUpdate({_id: req.body._id}, updateData, function(err, event){
if (err) {
res.send({"message": "Something went wrong!", "err": err, "status_code": "500"});
}
else {
console.log("----I AM IN ELSE STATEMENT----");
// WRITE DATA TO LOG FILE
fs.writeFile("/logs/update-event.txt", event, function(err) {
if(err) throw err;
res.send({"message": "success", "data": event, "status_code": "200"});
});
}
});
And following is the error I am getting when updating -
/home/myproject/controllers/events.js:71
if(err) throw err;
^
Error: ENOENT, open '/logs/update-event.txt'
Though If am using the following code, it is creating File at the root of the folder-
fs.writeFile("update-event.txt", event, function(err) {
I tried by manually creating logs
named folder but no luck.
Let me know what I am doing wrong here.
That obviously means, /logs/
directory is not existing: ENOENT
= Error No Entry.
And probably wrong path for the logs directory. /logs
is located in the root of the filesystem, not your application. Otherwise use logs/update-event.txt
w/o the leading /