0

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.

4
  • That obviously means, /logs/ directory is not existing: ENOENT = Error No Entry. Commented Aug 22, 2014 at 10:13
  • @AxelAmthor I tried by creating a logs directory but still the same error Commented Aug 22, 2014 at 10:15
  • 1
    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 / Commented Aug 22, 2014 at 10:17
  • @AxelAmthor Thx a ton..please post this as an answer and I will accept it as it solved my problem :) Commented Aug 22, 2014 at 10:19

1 Answer 1

2

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 /

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.