Skip to Content
APIexists

exists

Check if a path exists (file, directory, or symlink). Returns a boolean; does not distinguish type. Prefer stat if you need metadata.

Basic usage

import { exists } from '@rush-fs/core' const ok = await exists('./package.json') if (ok) await doSomething()

Methods

exists(path)

Async. Returns Promise<boolean>.

ArgumentTypeDescription
pathstringPath to check.

existsSync(path)

Sync. Returns boolean.

Performance

From repo benchmarks (pnpm build && pnpm bench):

ScenarioNode.jsRush-FSNote
existsSync (existing file)444 ns1.34 µsNode.js internal fast path

For sync “exists” checks on hot paths, Node.js can be faster; for async or batch use Rush-FS is fine.

Notes

  • Race: Between exists() and a subsequent operation the file may be deleted; prefer stat or try the operation and handle ENOENT when robustness matters.
  • Type: Use stat/lstat if you need to know whether the path is a file, directory, or symlink.
Last updated on