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>.
| Argument | Type | Description |
|---|---|---|
path | string | Path to check. |
existsSync(path)
Sync. Returns boolean.
Performance
From repo benchmarks (pnpm build && pnpm bench):
| Scenario | Node.js | Rush-FS | Note |
|---|---|---|---|
| existsSync (existing file) | 444 ns | 1.34 µs | Node.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; preferstator try the operation and handleENOENTwhen robustness matters. - Type: Use
stat/lstatif you need to know whether the path is a file, directory, or symlink.
Last updated on