Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fresh/src/dev/deps.ts>existsSync

The next-gen web framework.
Extremely Popular
Go to Latest
function existsSync
import { existsSync } from "https://deno.land/x/fresh@1.6.1/src/dev/deps.ts";

Test whether or not the given path exists by checking with the file system. Please consider to check if the path is readable and either a file or a directory by providing additional options:

import { existsSync } from "https://deno.land/std@0.224.0/fs/mod.ts";
const isReadableDir = existsSync("./foo", {
  isReadable: true,
  isDirectory: true
});
const isReadableFile = existsSync("./bar", {
  isReadable: true,
  isFile: true
});

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.

Bad:

import { existsSync } from "https://deno.land/std@0.224.0/fs/mod.ts";

if (existsSync("./foo")) {
  Deno.removeSync("./foo");
}

Good:

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

Parameters

path: string | URL
optional
options: ExistsOptions

Returns

boolean