Replacements for path-exists
Async fs.access (native, Node.js)
Use fs/promises.access and return a boolean.
ts
import pathExists from 'path-exists'
import { access } from 'node:fs/promises'
const exists = await pathExists('/etc/passwd')
const exists = await access('/etc/passwd').then(
() => true,
() => false
) Sync fs.existsSync (native, Node.js)
Added in v0.1.21: synchronous path/file existence check via fs.existsSync.
ts
import pathExists from 'path-exists'
import { existsSync } from 'node:fs'
const exists = await pathExists('/etc/passwd')
const exists = existsSync('/etc/passwd') Bun
Bun.file() returns a BunFile with an .exists() method.
ts
import pathExists from 'path-exists'
const path = '/path/to/package.json'
const exists = await pathExists(path)
const file = Bun.file(path)
const exists = await file.exists() // boolean