Bun

指南讀取檔案

使用 Bun 檢查檔案是否存在

Bun.file() 函式接受一個路徑並返回一個 BunFile 例項。使用 .exists() 方法來檢查給定路徑處的檔案是否存在。

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

await file.exists(); // boolean;

有關處理 BunFile 的更多資訊,請參閱 API > 檔案 I/O