How can one check if a file or directory exists using Deno?

There is the standard library implementation, here: https://deno.land/std/fs/mod.ts

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

const pathFound = existsSync(filePath)
console.log(pathFound)

This code will print true if the path exists and false if not.

And this is the async implementation:

import {exists} from "https://deno.land/std/fs/mod.ts"

exists(filePath).then((result : boolean) => console.log(result))

Make sure you run deno with the unstable flag and grant access to that file:

deno run --unstable  --allow-read={filePath} index.ts

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)