| description | Modern alternatives to the path-exists package for checking if a path exists |
|---|
Use fs/promises.access and return a boolean.
import pathExists from 'path-exists' // [!code --]
import { access } from 'node:fs/promises' // [!code ++]
const exists = await pathExists('/etc/passwd') // [!code --]
const exists = await access('/etc/passwd').then( // [!code ++]
() => true, // [!code ++]
() => false // [!code ++]
) // [!code ++]Added in v0.1.21: synchronous path/file existence check via fs.existsSync.
import pathExists from 'path-exists' // [!code --]
import { existsSync } from 'node:fs' // [!code ++]
const exists = await pathExists('/etc/passwd') // [!code --]
const exists = existsSync('/etc/passwd') // [!code ++]Bun.file() returns a BunFile with an .exists() method.
import pathExists from 'path-exists' // [!code --]
const path = '/path/to/package.json'
const exists = await pathExists(path) // [!code --]
const file = Bun.file(path) // [!code ++]
const exists = await file.exists() // boolean [!code ++]