On Wed, Aug 22, 2012 at 12:54 PM, Alexey Petrushin
<[email protected]> wrote:
> By the way, why "checking for existence is 'anti-pattern'"? Can You please
> give a link to the detailed description of such case?

Because if you're going to do anything with the file after checking
for it, why not just try to do the thing in the first place.  It's a
race condition anyway.  The file might disappear between checking for
it and trying to use it.  At least with fs.stat you get the
information about the file if it exists, and a detailed error object
if it doesn't.  Performance wise, this is the same number of syscalls
and less JS function calls. (fs.exists is just a wrapper around
fs.stat anyway)  Also fs.exists lies sometimes.  Since it can only
return a true or false, what should it do if the file exists, but
you're not able to read it?  What if you're not able to enter it's
parent directory?
>
> --
> 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

Reply via email to