From 4c89c60867591b50e0b31bf5009fd5ad6a3cebe1 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 26 Jul 2023 14:59:39 -0700 Subject: Add files (#3826) --- docs/guides/read-file/exists.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 docs/guides/read-file/exists.md (limited to 'docs/guides/read-file/exists.md') diff --git a/docs/guides/read-file/exists.md b/docs/guides/read-file/exists.md new file mode 100644 index 000000000..fd6cbbf9a --- /dev/null +++ b/docs/guides/read-file/exists.md @@ -0,0 +1,16 @@ +--- +name: Check if a file exists +--- + +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. + +```ts +const path = "/path/to/package.json"; +const file = Bun.file(path); + +file.exists(); // boolean; +``` + +--- + +Refer to [API > File I/O](/docs/api/file-io) for more information on working with `BunFile`. -- cgit v1.2.3