Checking "err.code" for "ENOENT" is the most cross-platform and backwards compatible way to check for the existence of the file.
On Wed, Aug 22, 2012 at 1:29 PM, Jimb Esser <[email protected]> wrote: > Yeah, there are a lot of cases where "does not exists" as an "error" needs > to be treated differently. I tried making a "read from this file, return a > default value if it does not exist" function without using fs.exists, and > was unable to do so efficiently without relying on undocumented error code > values [1]. It's very unclear if that code will work on different versions > of node let alone different operating systems. It's vitally important in > cases like "rename this file to a backup before overwriting" that an "error" > in the process is treated differently than "file does not exists", so > fs.exists does serve a purpose, even if its signature could have been > designed in a more conformant manner. > > [1] https://gist.github.com/3429037 > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
