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

x/ayonli_jsext/fs.ts>exists

A JavaScript extension package for building strong and modern applications.
Latest
function exists
import { exists } from "https://deno.land/x/ayonli_jsext@v0.9.72/fs.ts";

Checks if the given path exists.

This function may throw an error if the path is invalid or the operation is not allowed.

NOTE: This function can also be used in Cloudflare Workers.

Examples

Example 1

// with the default storage
import { exists } from "@ayonli/jsext/fs";

if (await exists("/path/to/file.txt")) {
    console.log("The file exists.");
} else {
    console.log("The file does not exist.");
}

Example 2

// with a user-selected directory as root (Chromium only)
import { exists } from "@ayonli/jsext/fs";

const root = await window.showDirectoryPicker();

if (await exists("/path/to/file.txt", { root })) {
    console.log("The file exists.");
} else {
    console.log("The file does not exist.");
}

Parameters

path: string
optional
options: FileSystemOptions = [UNSUPPORTED]

Returns

Promise<boolean>