Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/node-core-library > FileSystem > exists

FileSystem.exists() method

Returns true if the path exists on disk. Behind the scenes it uses fs.existsSync().

Signature:

static exists(path: string): boolean;

Parameters

ParameterTypeDescription
pathstringThe absolute or relative path to the filesystem object.

Returns:

boolean

Remarks

There is a debate about the fact that after fs.existsSync() returns true, the file might be deleted before fs.readSync() is called, which would imply that everybody should catch a readSync() exception, and nobody should ever use fs.existsSync(). We find this to be unpersuasive, since "unexceptional exceptions" really hinder the break-on-exception debugging experience. Also, throwing/catching is generally slow.