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 的資訊。