path-exists
is a simple utility that can be replaced with platform-provided APIs.
Added in v0.1.21, fs.existsSync
can be used to check if a path exists. It is synchronous and returns a boolean.
import { existsSync } from 'node:fs';
if (existsSync('/etc/passwd'))
console.log('The path exists.');
The Bun.file()
function accepts a path and returns a BunFile instance.
const path = "/path/to/package.json";
const file = Bun.file(path);
await file.exists(); // boolean;