Catch fs.readFileSync error

Posted on
  • How can i catch an fs.readFileSync error if a requested file is not available on sd-card? Right now i get the same result for an empty file and if the file is not available.

  • You can't at the moment - the best you could do is require("fs").readdir().indexOf("foo")>=­0

    Perhaps it should return undefined rather than an empty string if the file doesn't exist?

  • I would prefer to get a 'undefined' instead of an empty string. This way its easier and cleaner to decide if the operation was successful and what actions to take. e.g. send 200 vs. 404.

  • fs.readFileSync in v1.51 now returns undefined if the file is not found. Thanks a lot Gordon.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Catch fs.readFileSync error

Posted by Avatar for loopMasta @loopMasta

Actions