fs/promises API. You can import it using the ant:fs specifier or the Node-compatible node:fs and fs specifiers — all three point to the same implementation. Functions return promises by default, so you can use await directly without touching a callback-style API.
Importing the module
- ant:fs (recommended)
- ant:fs/promises
- node:fs
ant:fs in new code to make the runtime dependency explicit.
Reading files
As a Buffer
readFile without an encoding option returns a Buffer — a Node-compatible subclass of Uint8Array.
As a string
Pass'utf8' as the second argument to get a decoded string instead.
Writing files
Write a new file
Append to a file
Checking if a file exists
existsSync is synchronous. Use it for quick existence checks before performing async operations.
File metadata
Directory operations
Create a directory
{ recursive: true } to create any missing parent directories — equivalent to mkdir -p.
List directory contents
Deleting and renaming
Delete a file
Rename or move a file
API reference
Reads a file. Returns
Promise<Buffer> without an encoding, or Promise<string> when encoding is 'utf8'.Writes
data to path, overwriting any existing file. Returns Promise<void>.Appends
data to path, creating the file if it does not exist. Returns Promise<void>.Returns
Promise<Stats> with file metadata including size, mtime, isFile(), and isDirectory().Creates a directory. Pass
{ recursive: true } to create missing parents. Returns Promise<void>.Lists files and directories in
path. Returns Promise<string[]>.Deletes a file. Returns
Promise<void>.Renames or moves a file. Returns
Promise<void>.Returns
true if the path exists. Synchronous — no promise needed.The ant:path module
Use ant:path to build file paths safely across platforms. Import it alongside ant:fs.
Joins path segments using the OS separator and normalizes the result.
Resolves a sequence of paths into an absolute path.
Returns the directory portion of a path.
Returns the last component of a path (the filename).
Returns the file extension, including the dot (e.g.
".ts").