Skip to content

fs: un-deprecate existsSync(), throw error on EPERM

This is my conclusion from https://github.com/nodejs/node/issues/1592#issuecomment-159143911.

A significant amount of people find specifically existsSync() useful (especially in simple CLI apps) and it seems unreasonable to require a module for this. Keep exists() deprecated as it breaks our errback API convention.

This commit makes existsSync() throw on EPERM. The technical problem with existsSync() (besides a race condition if used badly) is that you cannot know if a file does or doesn't exist under Windows with improper permissions. Throwing in that case really isn't that bad of an idea, since the regular output will probably cause errors anyways down the line, and I don't think these errors can be remedied from Node.js. Instead, error so the end user can clean up their file permissions. Catching this error in user code isn't really worthwhile due to these reasons, so suggest against it.

Discuss. cc @nodejs/collaborators

Merge request reports

Loading