Sunday, 29 December 2019

writeFile no such file or directory

I have a file(data.file an image), I would like to save this image. Now an image with the same name could exist before it. I would like to overwrite if so or create it if it does not exist since before. I read that the flag "w" should do this.

Code:

fs.writeFile('/avatar/myFile.png', data.file, {
  flag: "w"
}, function(err) {
  if (err) {
    return console.log(err);
  }
  console.log("The file was saved!");
});

Error:

[Error: ENOENT: no such file or directory, open '/avatar/myFile.png']
errno: -2,
  code: 'ENOENT',
    syscall: 'open',
      path: '/avatar/myFile.png'


from writeFile no such file or directory

No comments:

Post a Comment