Guides · File System
Check if a file exists
Check whether a file exists at a given path with the .exists() method of a BunFile.
The Bun.file() function accepts a path and returns a BunFile instance. Use the .exists() method to check if a file exists at the given path.
index.ts
const path = "/path/to/package.json";
const file = Bun.file(path);
await file.exists(); // boolean;
See File I/O for more on working with BunFile.