Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback


The Deno Standard Library
Go to Latest
function existsSync
import { existsSync } from "";

Synchronously test whether or not the given path exists by checking with the file system.

Note: Do not use this function if performing a check before another operation on that file. Doing so creates a race condition. Instead, perform the actual file operation directly. This function is not recommended for this use case. See the recommended method below.


Recommended method

// Notice no use of exists
try {
  Deno.removeSync("./foo", { recursive: true });
} catch (error) {
  if (!(error instanceof Deno.errors.NotFound)) {
    throw error;
  // Do nothing...

Notice that existsSync() is not used in the above example. Doing so avoids a possible race condition. See the above section for details.

Basic usage

import { existsSync } from "";

existsSync("./exists"); // true
existsSync("./does_not_exist"); // false

Check if a path is readable

import { existsSync } from "";

existsSync("./readable", { isReadable: true }); // true
existsSync("./not_readable", { isReadable: true }); // false

Check if a path is a directory

import { existsSync } from "";

existsSync("./directory", { isDirectory: true }); // true
existsSync("./file", { isDirectory: true }); // false

Check if a path is a file

import { existsSync } from "";

existsSync("./file", { isFile: true }); // true
existsSync("./directory", { isFile: true }); // false

Check if a path is a readable directory

import { existsSync } from "";

existsSync("./readable_directory", { isReadable: true, isDirectory: true }); // true
existsSync("./not_readable_directory", { isReadable: true, isDirectory: true }); // false

Check if a path is a readable file

import { existsSync } from "";

existsSync("./readable_file", { isReadable: true, isFile: true }); // true
existsSync("./not_readable_file", { isReadable: true, isFile: true }); // false


path: string | URL

The path to the file or directory, as a string or URL.

options: ExistsOptions

Additional options for the check.



true if the path exists, false otherwise.