Bun

指南讀取檔案

使用 Bun 檢查檔案是否存在

Bun.file() 函式接受路徑並傳回 BunFile 執行個體。使用 .exists() 方法檢查檔案是否存在於指定的路徑。

const path = "/path/to/package.json";
const file = Bun.file(path);

await file.exists(); // boolean;

參閱 API > 檔案 I/O 以取得更多關於使用 BunFile 的資訊。