node:fs
Node-compatible synchronous and promise-based filesystem operations.
Available in vjs (vjs-lite omits promises and node:fs/promises,
providing synchronous operations only). Enabled by default unless
--no-node-compat is passed.
import ... from "node:fs"
node-compat (enabled by default; disable with --no-node-compat)fs.promises (FsPromises) is V8-only (vjs). Synchronous *Sync APIs work on both vjs and vjs-lite.Example
Section titled “Example”import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
mkdirSync("/tmp/vael-fs-demo", { recursive: true });writeFileSync("/tmp/vael-fs-demo/hello.txt", "hello vaeljs", "utf8");console.log(readFileSync("/tmp/vael-fs-demo/hello.txt", "utf8"));rmSync("/tmp/vael-fs-demo", { recursive: true, force: true });readFileSyncv0.0.0-alpha.0path as bytes.writeFileSyncv0.0.0-alpha.0data to path, replacing the file if it already exists.appendFileSyncv0.0.0-alpha.0data to path, creating the file if it does not exist.existsSyncv0.0.0-alpha.0true if path exists.statSyncv0.0.0-alpha.0Stats for path, following symbolic links.lstatSyncv0.0.0-alpha.0Stats for path, without following symbolic links.readdirSyncv0.0.0-alpha.0mkdirSyncv0.0.0-alpha.0path.rmSyncv0.0.0-alpha.0path.unlinkSyncv0.0.0-alpha.0path.renameSyncv0.0.0-alpha.0oldPath to newPath.copyFileSyncv0.0.0-alpha.0src to dest.realpathSyncv0.0.0-alpha.0path.mkdtempSyncv0.0.0-alpha.0prefix.openSyncv0.0.0-alpha.2path and return a numeric file descriptor.readSyncv0.0.0-alpha.2fd into buffer.writeSyncv0.0.0-alpha.2buffer to file descriptor fd.closeSyncv0.0.0-alpha.2fd.fstatSyncv0.0.0-alpha.2Stats for open file descriptor fd.fsyncSyncv0.0.0-alpha.2fd to storage.ftruncateSyncv0.0.0-alpha.2fd to len bytes.truncateSyncv0.0.0-alpha.2path to len bytes.accessSyncv0.0.0-alpha.2path, throwing if inaccessible.symlinkSyncv0.0.0-alpha.2path pointing to target.readlinkSyncv0.0.0-alpha.2path as a string.chmodSyncv0.0.0-alpha.2path.cpSyncv0.0.0-alpha.2src to dest.createReadStreamvjs onlyv0.0.0-alpha.2path.createWriteStreamvjs onlyv0.0.0-alpha.2path.watchvjs onlyv0.0.0-alpha.2filename (file or directory) for changes.Statsv0.0.0-alpha.0statSync, lstatSync, stat, and lstat.Direntv0.0.0-alpha.0readdirSync / readdir with withFileTypes: true.FsConstantsv0.0.0-alpha.0AbortSignalLikevjs onlyv0.0.0-alpha.2watch().ReadSyncOptionsv0.0.0-alpha.2readSync().CpOptionsv0.0.0-alpha.2cpSync() and promises.cp().ReadStreamOptionsvjs onlyv0.0.0-alpha.2createReadStream().WriteStreamOptionsvjs onlyv0.0.0-alpha.2createWriteStream().ReadStreamvjs onlyv0.0.0-alpha.2createReadStream().WriteStreamvjs onlyv0.0.0-alpha.2createWriteStream().WatchOptionsvjs onlyv0.0.0-alpha.2watch().FSWatchervjs onlyv0.0.0-alpha.2fs.watch().FileChangeInfovjs onlyv0.0.0-alpha.2fs.promises.watch().FileHandlevjs onlyv0.0.0-alpha.2promises.open().FsPromisesvjs onlyv0.0.0-alpha.0fs.promises.Functions
Section titled “Functions”readFileSync
Section titled “readFileSync”export function readFileSync(path: PathInput, options?: { encoding?: null | undefined } | null): Uint8Array;
export function readFileSync(path: PathInput, options: TextEncoding | { encoding: TextEncoding }): string;
Synchronously read the entire contents of path as bytes.
Synchronously read the entire contents of path as an encoded string.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
options optional | { encoding?: null | undefined } | null | TextEncoding | { encoding: TextEncoding } | Optional object with encoding: null | undefined (or null); Encoding name or { encoding } object. |
Uint8Array—Buffer(Uint8Arraysubclass) containing the file bytes.string— Decoded string contents of the file.
TypeError— on invalidpathoroptionstypes; on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).Error— withcode"ENOENT","EACCES","EISDIR","EINVAL","ERR_FS_FILE_TOO_LARGE", or"EIO".
import { readFileSync } from "node:fs";
const raw = readFileSync("/etc/hosts");console.log(raw.byteLength);writeFileSync
Section titled “writeFileSync”export function writeFileSync(path: PathInput, data: string | Uint8Array | ArrayBufferView, options?: TextEncoding | { encoding?: TextEncoding | null }): void;
Synchronously write data to path, replacing the file if it already exists.
| Name | Type | Description |
|---|---|---|
path | PathInput | Destination filesystem path or file:// URL. |
data | string | Uint8Array | ArrayBufferView | String or byte view to write. |
options optional | TextEncoding | { encoding?: TextEncoding | null } | Encoding for string data (default "utf8") or options object. |
voidTypeError— on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).Error— withcode"ENOENT","EACCES","EISDIR","EINVAL", or"EIO".
import { readFileSync, writeFileSync } from "node:fs";
writeFileSync("/tmp/vael-note.txt", "saved", "utf8");console.log(readFileSync("/tmp/vael-note.txt", "utf8"));appendFileSync
Section titled “appendFileSync”export function appendFileSync(path: PathInput, data: string | Uint8Array | ArrayBufferView, options?: TextEncoding | { encoding?: TextEncoding | null }): void;
Synchronously append data to path, creating the file if it does not exist.
| Name | Type | Description |
|---|---|---|
path | PathInput | Destination filesystem path or file:// URL. |
data | string | Uint8Array | ArrayBufferView | String or byte view to append. |
options optional | TextEncoding | { encoding?: TextEncoding | null } | Encoding for string data (default "utf8") or options object. |
voidTypeError— on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).Error— withcode"ENOENT","EACCES","EISDIR","EINVAL", or"EIO".
existsSync
Section titled “existsSync”export function existsSync(path: PathInput): boolean;
Synchronously return true if path exists.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
boolean — true if path exists, otherwise false.TypeError— whenpathhas an invalid type.Error— withcode = "EINVAL"ifpathis invalid (for example, contains a NUL byte).
import { existsSync } from "node:fs";
console.log(existsSync("/tmp"));statSync
Section titled “statSync”export function statSync(path: PathInput): Stats;
Synchronously return Stats for path, following symbolic links.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
Stats — Stats metadata for the resolved entry.TypeError— whenpathhas an invalid type.Error— withcode"ENOENT","EACCES","EINVAL", or"EIO".
import { statSync } from "node:fs";
const info = statSync("/tmp");console.log(info.isDirectory(), info.size);lstatSync
Section titled “lstatSync”export function lstatSync(path: PathInput): Stats;
Synchronously return Stats for path, without following symbolic links.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
Stats — Stats metadata for the entry itself (including symlinks).TypeError— whenpathhas an invalid type.Error— withcode"ENOENT","EACCES","EINVAL", or"EIO".
readdirSync
Section titled “readdirSync”export function readdirSync(path: PathInput, options?: { withFileTypes?: false }): string[];
export function readdirSync(path: PathInput, options: { withFileTypes: true }): Dirent[];
Synchronously read directory entry names.
Synchronously read directory entries as Dirent objects.
| Name | Type | Description |
|---|---|---|
path | PathInput | Directory path or file:// URL. |
options optional | { withFileTypes?: false } | { withFileTypes: true } | Optional { withFileTypes?: false }; { withFileTypes: true }. |
string[]— Array of entry names insidepath.Dirent[]— Array ofDirentobjects insidepath.
TypeError— whenpathhas an invalid type.Error— withcode"ENOENT","ENOTDIR","EACCES","EINVAL", or"EIO".
import { readdirSync } from "node:fs";
const entries = readdirSync("/tmp");console.log(entries.length);mkdirSync
Section titled “mkdirSync”export function mkdirSync(path: PathInput, options?: { recursive?: boolean }): void;
Synchronously create a directory at path.
| Name | Type | Description |
|---|---|---|
path | PathInput | Directory path or file:// URL. |
options optional | { recursive?: boolean } | Set recursive: true to create missing parent directories and succeed if already present. |
voidTypeError— whenpathhas an invalid type.Error— withcode"EEXIST","ENOENT","EACCES","EINVAL", or"EIO".
rmSync
Section titled “rmSync”export function rmSync(path: PathInput, options?: { recursive?: boolean; force?: boolean }): void;
Synchronously remove files and directories at path.
| Name | Type | Description |
|---|---|---|
path | PathInput | Target path or file:// URL. |
options optional | { recursive?: boolean; force?: boolean } | Set recursive: true to remove directory trees and force: true to ignore missing paths (ENOENT). |
voidTypeError— whenpathhas an invalid type.Error— withcode"ENOENT"(unlessforce: true),"EISDIR","ENOTEMPTY","EACCES","EINVAL", or"EIO".
unlinkSync
Section titled “unlinkSync”export function unlinkSync(path: PathInput): void;
Synchronously remove a file or symbolic link at path.
| Name | Type | Description |
|---|---|---|
path | PathInput | File or symlink path or file:// URL. |
voidTypeError— whenpathhas an invalid type.Error— withcode"ENOENT","EISDIR","EACCES","EINVAL", or"EIO".
renameSync
Section titled “renameSync”export function renameSync(oldPath: PathInput, newPath: PathInput): void;
Synchronously rename oldPath to newPath.
| Name | Type | Description |
|---|---|---|
oldPath | PathInput | Existing source path or file:// URL. |
newPath | PathInput | Destination path or file:// URL. |
voidTypeError— whenoldPathornewPathhas an invalid type.Error— withcode"ENOENT","EACCES","EINVAL", or"EIO".
copyFileSync
Section titled “copyFileSync”export function copyFileSync(src: PathInput, dest: PathInput, mode?: number): void;
Synchronously copy src to dest.
| Name | Type | Description |
|---|---|---|
src | PathInput | Source file path or file:// URL. |
dest | PathInput | Destination file path or file:// URL. |
mode optional | number | Optional bitmask (pass constants.COPYFILE_EXCL to fail with EEXIST if dest exists). |
voidTypeError— whensrcordesthas an invalid type.Error— withcode"ENOENT","EEXIST","EACCES","EINVAL", or"EIO".
realpathSync
Section titled “realpathSync”export function realpathSync(path: PathInput): string;
Synchronously compute the canonical pathname for path.
| Name | Type | Description |
|---|---|---|
path | PathInput | Path or file:// URL to canonicalize. |
string — Resolved canonical path string.TypeError— whenpathhas an invalid type.Error— withcode"ENOENT","EACCES","EINVAL", or"EIO".
mkdtempSync
Section titled “mkdtempSync”export function mkdtempSync(prefix: string): string;
Synchronously create a unique temporary directory starting with prefix.
Appends 6 random alphanumeric characters to prefix and creates the
directory (mode 0o700 on Unix). The parent directory must already exist.
| Name | Type | Description |
|---|---|---|
prefix | string | Path prefix for the new temporary directory. |
string — Path of the created temporary directory.TypeError— whenprefixis not a string.Error— withcode"EINVAL"(empty/NUL prefix),"ENOENT","EACCES", or"EIO".
import { mkdtempSync, rmSync } from "node:fs";
const dir = mkdtempSync("/tmp/vael-");console.log(dir);rmSync(dir, { recursive: true, force: true });openSync
Section titled “openSync”export function openSync(
path: PathInput,
flags?: string | number,
mode?: string | number,
): number;
Synchronously open path and return a numeric file descriptor.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
flags optional | string | number | Open flags string or numeric bitmask (default "r"). |
mode optional | string | number | POSIX file permissions when creating a file (default 0o666). |
number — Numeric file descriptor.readSync
Section titled “readSync”export function readSync(
fd: number,
buffer: ArrayBufferView,
offset?: number,
length?: number,
position?: number | null,
): number;
export function readSync(
fd: number,
buffer: ArrayBufferView,
options?: ReadSyncOptions,
): number;
Synchronously read bytes from file descriptor fd into buffer.
readSync(fd, buffer, offset?, length?, position?)| Name | Type | Description |
|---|---|---|
fd | number | Open file descriptor returned by openSync. |
buffer | ArrayBufferView | Destination ArrayBufferView. |
offset optional | number | Byte offset in buffer to start writing (default 0). |
length optional | number | Number of bytes to read. |
position optional | number | null | File position to read from (null uses current offset). |
number — Number of bytes read (0 at EOF).readSync(fd, buffer, options?)Synchronously read bytes from file descriptor fd into buffer using options.
| Name | Type | Description |
|---|---|---|
fd | number | Open file descriptor returned by openSync. |
buffer | ArrayBufferView | Destination ArrayBufferView. |
options optional | ReadSyncOptions | Read offset, length, and position options. |
number — Number of bytes read (0 at EOF).writeSync
Section titled “writeSync”export function writeSync(
fd: number,
buffer: ArrayBufferView,
offset?: number,
length?: number,
position?: number | null,
): number;
export function writeSync(
fd: number,
data: string,
position?: number | null,
encoding?: TextEncoding,
): number;
Synchronously write bytes from buffer to file descriptor fd.
writeSync(fd, buffer, offset?, length?, position?)| Name | Type | Description |
|---|---|---|
fd | number | Open file descriptor returned by openSync. |
buffer | ArrayBufferView | Source ArrayBufferView. |
offset optional | number | Byte offset in buffer to start reading (default 0). |
length optional | number | Number of bytes to write. |
position optional | number | null | File position to write at (null uses current offset). |
number — Number of bytes written.writeSync(fd, data, position?, encoding?)Synchronously write string data to file descriptor fd.
| Name | Type | Description |
|---|---|---|
fd | number | Open file descriptor returned by openSync. |
data | string | String to write. |
position optional | number | null | File position to write at (null uses current offset). |
encoding optional | TextEncoding | Character encoding for data (default "utf8"). |
number — Number of bytes written.closeSync
Section titled “closeSync”export function closeSync(fd: number): void;
Synchronously close an open file descriptor fd.
| Name | Type | Description |
|---|---|---|
fd | number | Open file descriptor returned by openSync. |
voidfstatSync
Section titled “fstatSync”export function fstatSync(fd: number): Stats;
Synchronously return Stats for open file descriptor fd.
| Name | Type | Description |
|---|---|---|
fd | number | Open file descriptor returned by openSync. |
fsyncSync
Section titled “fsyncSync”export function fsyncSync(fd: number): void;
Synchronously flush all modified file data and metadata for fd to storage.
| Name | Type | Description |
|---|---|---|
fd | number | Open file descriptor returned by openSync. |
voidftruncateSync
Section titled “ftruncateSync”export function ftruncateSync(fd: number, len?: number): void;
Synchronously truncate (or extend) the file referenced by fd to len bytes.
| Name | Type | Description |
|---|---|---|
fd | number | Open file descriptor returned by openSync. |
len optional | number | Target byte length (default 0). |
voidtruncateSync
Section titled “truncateSync”export function truncateSync(path: PathInput, len?: number): void;
Synchronously truncate (or extend) the file at path to len bytes.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
len optional | number | Target byte length (default 0). |
voidaccessSync
Section titled “accessSync”export function accessSync(path: PathInput, mode?: number): void;
Synchronously test user permissions for path, throwing if inaccessible.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
mode optional | number | Optional accessibility bitmask (F_OK, R_OK, W_OK, X_OK, default F_OK). |
voidsymlinkSync
Section titled “symlinkSync”export function symlinkSync(
target: PathInput,
path: PathInput,
type?: "dir" | "file" | "junction",
): void;
Synchronously create a symbolic link at path pointing to target.
| Name | Type | Description |
|---|---|---|
target | PathInput | Link target path. |
path | PathInput | Symbolic link path to create. |
type optional | "dir" | "file" | "junction" | Optional Windows symlink hint ("dir", "file", or "junction"). |
voidreadlinkSync
Section titled “readlinkSync”export function readlinkSync(
path: PathInput,
options?: TextEncoding | { encoding?: TextEncoding } | null,
): string;
export function readlinkSync(
path: PathInput,
options: "buffer" | { encoding: "buffer" },
): Uint8Array;
Synchronously read the target of the symbolic link at path as a string.
Synchronously read the target of the symbolic link at path as raw bytes.
| Name | Type | Description |
|---|---|---|
path | PathInput | Symbolic link path or file:// URL. |
options optional | TextEncoding | { encoding?: TextEncoding } | null | "buffer" | { encoding: "buffer" } | Optional encoding ("utf8" default); { encoding: "buffer" }. |
string— Symlink target string.Uint8Array— Symlink target asUint8Array.
chmodSync
Section titled “chmodSync”export function chmodSync(path: PathInput, mode: string | number): void;
Synchronously change the permissions of path.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
mode | string | number | Numeric or octal string file mode. |
voidcpSync
Section titled “cpSync”export function cpSync(src: PathInput, dest: PathInput, options?: CpOptions): void;
Synchronously copy files or directories from src to dest.
| Name | Type | Description |
|---|---|---|
src | PathInput | Source file or directory path. |
dest | PathInput | Destination path. |
options optional | CpOptions | Optional copy behavior (recursive, force, filter, etc.). |
voidcreateReadStream
Section titled “createReadStream”export function createReadStream(
path: PathInput,
options?: TextEncoding | ReadStreamOptions,
): ReadStream;
Open a readable stream for path.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
options optional | TextEncoding | ReadStreamOptions | Optional encoding or stream options. |
ReadStream — ReadStream instance.createWriteStream
Section titled “createWriteStream”export function createWriteStream(
path: PathInput,
options?: TextEncoding | WriteStreamOptions,
): WriteStream;
Open a writable stream for path.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
options optional | TextEncoding | WriteStreamOptions | Optional encoding or stream options. |
WriteStream — WriteStream instance.export function watch(
filename: PathInput,
options?: WatchOptions | TextEncoding,
listener?: WatchListener,
): FSWatcher;
export function watch(filename: PathInput, listener: WatchListener): FSWatcher;
Watch filename (file or directory) for changes.
watch(filename, options?, listener?)| Name | Type | Description |
|---|---|---|
filename | PathInput | Filesystem path or file:// URL to watch. |
options optional | WatchOptions | TextEncoding | Optional watch settings or encoding string. |
listener optional | WatchListener | Optional listener invoked on "change" events. |
FSWatcher — FSWatcher handle.watch(filename, listener)Watch filename (file or directory) for changes with a trailing listener.
| Name | Type | Description |
|---|---|---|
filename | PathInput | Filesystem path or file:// URL to watch. |
listener | WatchListener | Listener invoked on "change" events. |
FSWatcher — FSWatcher handle.Interfaces
Section titled “Interfaces”export interface Stats {
readonly size: number;
readonly mode: number;
readonly atimeMs: number;
readonly atime: Date;
readonly mtimeMs: number;
readonly mtime: Date;
readonly ctimeMs: number;
readonly ctime: Date;
readonly birthtimeMs: number;
readonly birthtime: Date;
isFile(): boolean;
isDirectory(): boolean;
isSymbolicLink(): boolean;
isFIFO(): boolean;
isSocket(): boolean;
isBlockDevice(): boolean;
isCharacterDevice(): boolean;
}
File metadata returned by statSync, lstatSync, stat, and lstat.
| Property | Type | Description | Since |
|---|---|---|---|
size readonly | number | Size of the file in bytes. | v0.0.0-alpha.0 |
mode readonly | number | POSIX file type and permissions bitmask. | v0.0.0-alpha.2 |
atimeMs readonly | number | Last access timestamp in milliseconds since the Unix epoch. | v0.0.0-alpha.2 |
atime readonly | Date | Last access timestamp as a Date instance. | v0.0.0-alpha.2 |
mtimeMs readonly | number | Last modification timestamp in milliseconds since the Unix epoch. | v0.0.0-alpha.0 |
mtime readonly | Date | Last modification timestamp as a Date instance. | v0.0.0-alpha.0 |
ctimeMs readonly | number | Last status change timestamp in milliseconds since the Unix epoch. | v0.0.0-alpha.2 |
ctime readonly | Date | Last status change timestamp as a Date instance. | v0.0.0-alpha.2 |
birthtimeMs readonly | number | File creation (birthtime) timestamp in milliseconds since the Unix epoch. | v0.0.0-alpha.2 |
birthtime readonly | Date | File creation (birthtime) timestamp as a Date instance. | v0.0.0-alpha.2 |
Stats.isFile
Section titled “Stats.isFile”isFile(): boolean;
Return true if the entry is a regular file.
boolean — true for a regular file, otherwise false.Stats.isDirectory
Section titled “Stats.isDirectory”isDirectory(): boolean;
Return true if the entry is a directory.
boolean — true for a directory, otherwise false.Stats.isSymbolicLink
Section titled “Stats.isSymbolicLink”isSymbolicLink(): boolean;
Return true if the entry is a symbolic link.
boolean — true for a symbolic link, otherwise false.Stats.isFIFO
Section titled “Stats.isFIFO”isFIFO(): boolean;
Return true if the entry is a FIFO (named pipe).
boolean — true for a FIFO, otherwise false.Stats.isSocket
Section titled “Stats.isSocket”isSocket(): boolean;
Return true if the entry is a socket.
boolean — true for a socket, otherwise false.Stats.isBlockDevice
Section titled “Stats.isBlockDevice”isBlockDevice(): boolean;
Return true if the entry is a block device.
boolean — true for a block device, otherwise false.Stats.isCharacterDevice
Section titled “Stats.isCharacterDevice”isCharacterDevice(): boolean;
Return true if the entry is a character device.
boolean — true for a character device, otherwise false.Dirent
Section titled “Dirent”export interface Dirent {
readonly name: string;
readonly parentPath: string;
isFile(): boolean;
isDirectory(): boolean;
isSymbolicLink(): boolean;
}
Directory entry returned by readdirSync / readdir with withFileTypes: true.
| Property | Type | Description | Since |
|---|---|---|---|
name readonly | string | Entry filename relative to the directory passed to readdirSync / readdir. | v0.0.0-alpha.0 |
parentPath readonly | string | Path to the parent directory containing this entry. | v0.0.0-alpha.2 |
Dirent.isFile
Section titled “Dirent.isFile”isFile(): boolean;
Return true if the entry is a regular file.
boolean — true for a regular file, otherwise false.Dirent.isDirectory
Section titled “Dirent.isDirectory”isDirectory(): boolean;
Return true if the entry is a directory.
boolean — true for a directory, otherwise false.Dirent.isSymbolicLink
Section titled “Dirent.isSymbolicLink”isSymbolicLink(): boolean;
Return true if the entry is a symbolic link.
boolean — true for a symbolic link, otherwise false.FsConstants
Section titled “FsConstants”export interface FsConstants {
readonly F_OK: number;
readonly R_OK: number;
readonly W_OK: number;
readonly X_OK: number;
readonly COPYFILE_EXCL: number;
readonly COPYFILE_FICLONE: number;
readonly COPYFILE_FICLONE_FORCE: number;
}
Filesystem access and copy mode constants.
| Property | Type | Description | Since |
|---|---|---|---|
F_OK readonly | number | Flag testing existence of the path (0). | v0.0.0-alpha.0 |
R_OK readonly | number | Flag testing read permission (4). | v0.0.0-alpha.0 |
W_OK readonly | number | Flag testing write permission (2). | v0.0.0-alpha.0 |
X_OK readonly | number | Flag testing execute permission (1). | v0.0.0-alpha.0 |
COPYFILE_EXCL readonly | number | Copy flag failing if the destination file already exists (1). | v0.0.0-alpha.0 |
COPYFILE_FICLONE readonly | number | Copy flag requesting copy-on-write reflink if supported (2). | v0.0.0-alpha.0 |
COPYFILE_FICLONE_FORCE readonly | number | Copy flag requiring copy-on-write reflink (4). | v0.0.0-alpha.0 |
AbortSignalLike
Section titled “AbortSignalLike”export interface AbortSignalLike {
readonly aborted: boolean;
readonly reason?: unknown;
addEventListener(type: string, listener: (...args: any[]) => void, options?: { once?: boolean }): void;
removeEventListener?(type: string, listener: (...args: any[]) => void): void;
}
Minimal abort-signal contract accepted by watch().
| Property | Type | Description | Since |
|---|---|---|---|
aborted readonly | boolean | Whether the signal has already been aborted. | v0.0.0-alpha.2 |
reason readonly optional | unknown | Optional abort reason value. | v0.0.0-alpha.2 |
AbortSignalLike.addEventListener
Section titled “AbortSignalLike.addEventListener”addEventListener(type: string, listener: (...args: any[]) => void, options?: { once?: boolean }): void;
Register an "abort" listener.
| Name | Type | Description |
|---|---|---|
type | string | Event type ("abort"). |
listener | (...args: any[]) => void | Callback invoked on abort. |
options optional | { once?: boolean } | Optional listener options. |
voidAbortSignalLike.removeEventListener
Section titled “AbortSignalLike.removeEventListener”removeEventListener?(type: string, listener: (...args: any[]) => void): void;
Unregister an "abort" listener.
| Name | Type | Description |
|---|---|---|
type | string | Event type ("abort"). |
listener | (...args: any[]) => void | Callback to remove. |
voidReadSyncOptions
Section titled “ReadSyncOptions”export interface ReadSyncOptions {
offset?: number;
length?: number;
position?: number | null;
}
Options accepted by readSync().
| Property | Type | Description | Since |
|---|---|---|---|
offset optional | number | Byte offset within buffer to start writing (default 0). | v0.0.0-alpha.2 |
length optional | number | Maximum number of bytes to read (default buffer.byteLength - offset). | v0.0.0-alpha.2 |
position optional | number | null | File position to read from (null uses current file offset). | v0.0.0-alpha.2 |
CpOptions
Section titled “CpOptions”export interface CpOptions {
dereference?: boolean;
errorOnExist?: boolean;
filter?: (source: string, destination: string) => boolean | Promise<boolean>;
force?: boolean;
recursive?: boolean;
preserveTimestamps?: boolean;
verbatimSymlinks?: boolean;
}
Options accepted by cpSync() and promises.cp().
| Property | Type | Description | Since |
|---|---|---|---|
dereference optional | boolean | Dereference symbolic links during copy. | v0.0.0-alpha.2 |
errorOnExist optional | boolean | Throw ERR_FS_CP_EEXIST when force is false and target exists. | v0.0.0-alpha.2 |
filter optional | (source: string, destination: string) => boolean | Promise<boolean> | Filter predicate (src, dest) => boolean | Promise<boolean>. | v0.0.0-alpha.2 |
force optional | boolean | Overwrite existing files (default true). | v0.0.0-alpha.2 |
recursive optional | boolean | Copy directories recursively (default false). | v0.0.0-alpha.2 |
preserveTimestamps optional | boolean | Preserve file timestamps when true. | v0.0.0-alpha.2 |
verbatimSymlinks optional | boolean | Preserve symlink behavior without following links. | v0.0.0-alpha.2 |
ReadStreamOptions
Section titled “ReadStreamOptions”export interface ReadStreamOptions {
flags?: string;
encoding?: TextEncoding | null;
fd?: number;
mode?: number;
autoClose?: boolean;
emitClose?: boolean;
start?: number;
end?: number;
highWaterMark?: number;
}
Options accepted by createReadStream().
| Property | Type | Description | Since |
|---|---|---|---|
flags optional | string | Open flags string (default "r"). | v0.0.0-alpha.2 |
encoding optional | TextEncoding | null | Output string encoding (null for raw Buffer). | v0.0.0-alpha.2 |
fd optional | number | Existing open file descriptor to wrap instead of opening path. | v0.0.0-alpha.2 |
mode optional | number | File mode if creating a file (default 0o666). | v0.0.0-alpha.2 |
autoClose optional | boolean | Automatically close the file descriptor on end/error (default true). | v0.0.0-alpha.2 |
emitClose optional | boolean | Emit "close" after stream destruction (default true). | v0.0.0-alpha.2 |
start optional | number | Starting byte offset in the file (inclusive). | v0.0.0-alpha.2 |
end optional | number | Ending byte offset in the file (inclusive). | v0.0.0-alpha.2 |
highWaterMark optional | number | Internal read chunk size in bytes (default 65536). | v0.0.0-alpha.2 |
WriteStreamOptions
Section titled “WriteStreamOptions”export interface WriteStreamOptions {
flags?: string;
encoding?: TextEncoding;
fd?: number;
mode?: number;
autoClose?: boolean;
emitClose?: boolean;
start?: number;
highWaterMark?: number;
flush?: boolean;
}
Options accepted by createWriteStream().
| Property | Type | Description | Since |
|---|---|---|---|
flags optional | string | Open flags string (default "w"). | v0.0.0-alpha.2 |
encoding optional | TextEncoding | Default encoding for written strings (default "utf8"). | v0.0.0-alpha.2 |
fd optional | number | Existing open file descriptor to wrap instead of opening path. | v0.0.0-alpha.2 |
mode optional | number | POSIX file mode when creating a file (default 0o666). | v0.0.0-alpha.2 |
autoClose optional | boolean | Automatically close the file descriptor on finish/error (default true). | v0.0.0-alpha.2 |
emitClose optional | boolean | Emit "close" after stream destruction (default true). | v0.0.0-alpha.2 |
start optional | number | Starting byte offset in the file. | v0.0.0-alpha.2 |
highWaterMark optional | number | Internal write buffer high-water mark in bytes. | v0.0.0-alpha.2 |
flush optional | boolean | Flush file data to storage before closing. | v0.0.0-alpha.2 |
ReadStream
Section titled “ReadStream”export interface ReadStream {
readonly bytesRead: number;
readonly path: string | Uint8Array;
readonly pending: boolean;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
pause(): this;
resume(): this;
pipe<T extends { write(chunk: any, ...args: any[]): any; end(...args: any[]): any }>(
destination: T,
options?: { end?: boolean },
): T;
close(callback?: (err?: Error | null) => void): void;
destroy(error?: Error): this;
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
}
Readable file stream returned by createReadStream().
| Property | Type | Description | Since |
|---|---|---|---|
bytesRead readonly | number | Total bytes read from the file so far. | v0.0.0-alpha.2 |
path readonly | string | Uint8Array | Path passed to createReadStream(). | v0.0.0-alpha.2 |
pending readonly | boolean | Whether the stream is currently waiting for the file to open. | v0.0.0-alpha.2 |
ReadStream.on
Section titled “ReadStream.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisReadStream.once
Section titled “ReadStream.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisReadStream.off
Section titled “ReadStream.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove a stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisReadStream.pause
Section titled “ReadStream.pause”pause(): this;
Pause "data" events.
thisReadStream.resume
Section titled “ReadStream.resume”resume(): this;
Resume "data" events.
thisReadStream.pipe
Section titled “ReadStream.pipe”pipe<T extends { write(chunk: any, ...args: any[]): any; end(...args: any[]): any }>(
destination: T,
options?: { end?: boolean },
): T;
Pipe stream chunks into destination.
| Name | Type | Description |
|---|---|---|
destination | T | — |
options optional | { end?: boolean } | — |
TReadStream.close
Section titled “ReadStream.close”close(callback?: (err?: Error | null) => void): void;
Close and destroy the stream.
| Name | Type | Description |
|---|---|---|
callback optional | (err?: Error | null) => void | — |
voidReadStream.destroy
Section titled “ReadStream.destroy”destroy(error?: Error): this;
Destroy the stream.
| Name | Type | Description |
|---|---|---|
error optional | Error | — |
thisReadStream.[Symbol.asyncIterator]
Section titled “ReadStream.[Symbol.asyncIterator]”[Symbol.asyncIterator](): AsyncIterableIterator<any>;
Iterate asynchronously over file chunks.
WriteStream
Section titled “WriteStream”export interface WriteStream {
readonly bytesWritten: number;
readonly path: string | Uint8Array;
readonly pending: boolean;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
write(chunk: string | Uint8Array | ArrayBufferView, callback?: (err?: Error | null) => void): boolean;
write(chunk: string, encoding: TextEncoding, callback?: (err?: Error | null) => void): boolean;
end(callback?: () => void): this;
end(chunk: string | Uint8Array | ArrayBufferView, callback?: () => void): this;
close(callback?: (err?: Error | null) => void): void;
destroy(error?: Error): this;
}
Writable file stream returned by createWriteStream().
| Property | Type | Description | Since |
|---|---|---|---|
bytesWritten readonly | number | Total bytes written to the file so far. | v0.0.0-alpha.2 |
path readonly | string | Uint8Array | Path passed to createWriteStream(). | v0.0.0-alpha.2 |
pending readonly | boolean | Whether the stream is currently waiting for the file to open. | v0.0.0-alpha.2 |
WriteStream.on
Section titled “WriteStream.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisWriteStream.once
Section titled “WriteStream.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisWriteStream.off
Section titled “WriteStream.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove a stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisWriteStream.write
Section titled “WriteStream.write”write(chunk: string | Uint8Array | ArrayBufferView, callback?: (err?: Error | null) => void): boolean;
write(chunk: string, encoding: TextEncoding, callback?: (err?: Error | null) => void): boolean;
Write a string or byte chunk to the file.
write(chunk, callback?)| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | ArrayBufferView | — |
callback optional | (err?: Error | null) => void | — |
booleanwrite(chunk, encoding, callback?)Write a string chunk with explicit encoding to the file.
| Name | Type | Description |
|---|---|---|
chunk | string | — |
encoding | TextEncoding | — |
callback optional | (err?: Error | null) => void | — |
booleanWriteStream.end
Section titled “WriteStream.end”end(callback?: () => void): this;
end(chunk: string | Uint8Array | ArrayBufferView, callback?: () => void): this;
Finish writing and close the file stream.
end(callback?)| Name | Type | Description |
|---|---|---|
callback optional | () => void | — |
thisend(chunk, callback?)Write a final chunk and close the file stream.
| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | ArrayBufferView | — |
callback optional | () => void | — |
thisWriteStream.close
Section titled “WriteStream.close”close(callback?: (err?: Error | null) => void): void;
Close and destroy the stream.
| Name | Type | Description |
|---|---|---|
callback optional | (err?: Error | null) => void | — |
voidWriteStream.destroy
Section titled “WriteStream.destroy”destroy(error?: Error): this;
Destroy the stream.
| Name | Type | Description |
|---|---|---|
error optional | Error | — |
thisWatchOptions
Section titled “WatchOptions”export interface WatchOptions {
persistent?: boolean;
recursive?: boolean;
encoding?: TextEncoding | "buffer";
signal?: AbortSignalLike;
}
Options accepted by watch().
| Property | Type | Description | Since |
|---|---|---|---|
persistent optional | boolean | Keep the event loop active while watching (default true). | v0.0.0-alpha.2 |
recursive optional | boolean | Watch subdirectories recursively when true. | v0.0.0-alpha.2 |
encoding optional | TextEncoding | "buffer" | Character encoding for emitted filename strings. | v0.0.0-alpha.2 |
signal optional | AbortSignalLike | Optional abort signal stopping the watcher. | v0.0.0-alpha.2 |
FSWatcher
Section titled “FSWatcher”export interface FSWatcher {
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
close(): void;
ref(): this;
unref(): this;
}
Watcher handle returned by fs.watch().
FSWatcher.on
Section titled “FSWatcher.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a watcher event listener ("change", "error", "close").
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisFSWatcher.once
Section titled “FSWatcher.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time watcher event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisFSWatcher.off
Section titled “FSWatcher.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove a watcher event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisFSWatcher.close
Section titled “FSWatcher.close”close(): void;
Stop watching for filesystem changes.
voidFSWatcher.ref
Section titled “FSWatcher.ref”ref(): this;
Keep the event loop active while watching.
thisFSWatcher.unref
Section titled “FSWatcher.unref”unref(): this;
Allow the event loop to exit while watching.
thisFileChangeInfo
Section titled “FileChangeInfo”export interface FileChangeInfo {
eventType: "rename" | "change";
filename: string | null;
}
Change event object yielded by fs.promises.watch().
| Property | Type | Description | Since |
|---|---|---|---|
eventType | "rename" | "change" | Filesystem change event kind ("rename" or "change"). | v0.0.0-alpha.2 |
filename | string | null | Changed filename relative to the watched path, or null. | v0.0.0-alpha.2 |
FileHandle
Section titled “FileHandle”export interface FileHandle {
readonly fd: number;
read<T extends ArrayBufferView>(
buffer: T,
offset?: number | null,
length?: number | null,
position?: number | null,
): Promise<{ bytesRead: number; buffer: T }>;
write<T extends ArrayBufferView>(
buffer: T,
offset?: number | null,
length?: number | null,
position?: number | null,
): Promise<{ bytesWritten: number; buffer: T }>;
write(
data: string,
position?: number | null,
encoding?: TextEncoding,
): Promise<{ bytesWritten: number; buffer: string }>;
readFile(options?: { encoding?: null | undefined } | null): Promise<Uint8Array>;
readFile(options: TextEncoding | { encoding: TextEncoding }): Promise<string>;
writeFile(
data: string | Uint8Array | ArrayBufferView,
options?: TextEncoding | { encoding?: TextEncoding | null },
): Promise<void>;
appendFile(
data: string | Uint8Array | ArrayBufferView,
options?: TextEncoding | { encoding?: TextEncoding | null },
): Promise<void>;
stat(): Promise<Stats>;
sync(): Promise<void>;
datasync(): Promise<void>;
truncate(len?: number): Promise<void>;
chmod(mode: string | number): Promise<void>;
close(): Promise<void>;
[Symbol.asyncDispose](): Promise<void>;
}
Promise-based open file descriptor wrapper returned by promises.open().
| Property | Type | Description | Since |
|---|---|---|---|
fd readonly | number | Underlying numeric file descriptor. | v0.0.0-alpha.2 |
FileHandle.read
Section titled “FileHandle.read”read<T extends ArrayBufferView>(
buffer: T,
offset?: number | null,
length?: number | null,
position?: number | null,
): Promise<{ bytesRead: number; buffer: T }>;
Read bytes from the file handle into buffer.
| Name | Type | Description |
|---|---|---|
buffer | T | — |
offset optional | number | null | — |
length optional | number | null | — |
position optional | number | null | — |
Promise<{ bytesRead: number; buffer: T }>FileHandle.write
Section titled “FileHandle.write”write<T extends ArrayBufferView>(
buffer: T,
offset?: number | null,
length?: number | null,
position?: number | null,
): Promise<{ bytesWritten: number; buffer: T }>;
write(
data: string,
position?: number | null,
encoding?: TextEncoding,
): Promise<{ bytesWritten: number; buffer: string }>;
Write bytes from buffer to the file handle.
write(buffer, offset?, length?, position?)| Name | Type | Description |
|---|---|---|
buffer | T | — |
offset optional | number | null | — |
length optional | number | null | — |
position optional | number | null | — |
Promise<{ bytesWritten: number; buffer: T }>write(data, position?, encoding?)Write string data to the file handle.
| Name | Type | Description |
|---|---|---|
data | string | — |
position optional | number | null | — |
encoding optional | TextEncoding | — |
Promise<{ bytesWritten: number; buffer: string }>FileHandle.readFile
Section titled “FileHandle.readFile”readFile(options?: { encoding?: null | undefined } | null): Promise<Uint8Array>;
readFile(options: TextEncoding | { encoding: TextEncoding }): Promise<string>;
Read remaining contents of the handle as bytes.
Read remaining contents of the handle as a decoded string.
| Name | Type | Description |
|---|---|---|
options optional | { encoding?: null | undefined } | null | TextEncoding | { encoding: TextEncoding } | — |
Promise<Uint8Array>Promise<string>
FileHandle.writeFile
Section titled “FileHandle.writeFile”writeFile(
data: string | Uint8Array | ArrayBufferView,
options?: TextEncoding | { encoding?: TextEncoding | null },
): Promise<void>;
Write data to the file handle.
| Name | Type | Description |
|---|---|---|
data | string | Uint8Array | ArrayBufferView | — |
options optional | TextEncoding | { encoding?: TextEncoding | null } | — |
Promise<void>FileHandle.appendFile
Section titled “FileHandle.appendFile”appendFile(
data: string | Uint8Array | ArrayBufferView,
options?: TextEncoding | { encoding?: TextEncoding | null },
): Promise<void>;
Append data to the file handle.
| Name | Type | Description |
|---|---|---|
data | string | Uint8Array | ArrayBufferView | — |
options optional | TextEncoding | { encoding?: TextEncoding | null } | — |
Promise<void>FileHandle.stat
Section titled “FileHandle.stat”stat(): Promise<Stats>;
Return Stats for the open file handle.
FileHandle.sync
Section titled “FileHandle.sync”sync(): Promise<void>;
Flush modified file data and metadata to disk.
Promise<void>FileHandle.datasync
Section titled “FileHandle.datasync”datasync(): Promise<void>;
Flush modified file data (without metadata) to disk.
Promise<void>FileHandle.truncate
Section titled “FileHandle.truncate”truncate(len?: number): Promise<void>;
Truncate or extend the file to len bytes (default 0).
| Name | Type | Description |
|---|---|---|
len optional | number | — |
Promise<void>FileHandle.chmod
Section titled “FileHandle.chmod”chmod(mode: string | number): Promise<void>;
Change file permissions on the open handle.
| Name | Type | Description |
|---|---|---|
mode | string | number | — |
Promise<void>FileHandle.close
Section titled “FileHandle.close”close(): Promise<void>;
Close the file handle.
Promise<void>FileHandle.[Symbol.asyncDispose]
Section titled “FileHandle.[Symbol.asyncDispose]”[Symbol.asyncDispose](): Promise<void>;
Close the file handle automatically on await using.
Promise<void>FsPromises
Section titled “FsPromises”export interface FsPromises {
readFile(path: PathInput, options?: { encoding?: null | undefined } | null): Promise<Uint8Array>;
readFile(path: PathInput, options: TextEncoding | { encoding: TextEncoding }): Promise<string>;
writeFile(path: PathInput, data: string | Uint8Array | ArrayBufferView, options?: TextEncoding | { encoding?: TextEncoding | null }): Promise<void>;
appendFile(path: PathInput, data: string | Uint8Array | ArrayBufferView, options?: TextEncoding | { encoding?: TextEncoding | null }): Promise<void>;
stat(path: PathInput): Promise<Stats>;
lstat(path: PathInput): Promise<Stats>;
readdir(path: PathInput, options?: { withFileTypes?: false }): Promise<string[]>;
readdir(path: PathInput, options: { withFileTypes: true }): Promise<Dirent[]>;
mkdir(path: PathInput, options?: { recursive?: boolean }): Promise<void>;
rm(path: PathInput, options?: { recursive?: boolean; force?: boolean }): Promise<void>;
unlink(path: PathInput): Promise<void>;
rename(oldPath: PathInput, newPath: PathInput): Promise<void>;
copyFile(src: PathInput, dest: PathInput, mode?: number): Promise<void>;
realpath(path: PathInput): Promise<string>;
mkdtemp(prefix: string): Promise<string>;
open(path: PathInput, flags?: string | number, mode?: string | number): Promise<FileHandle>;
access(path: PathInput, mode?: number): Promise<void>;
symlink(target: PathInput, path: PathInput, type?: "dir" | "file" | "junction"): Promise<void>;
readlink(path: PathInput, options?: TextEncoding | { encoding?: TextEncoding } | null): Promise<string>;
readlink(path: PathInput, options: "buffer" | { encoding: "buffer" }): Promise<Uint8Array>;
chmod(path: PathInput, mode: string | number): Promise<void>;
cp(src: PathInput, dest: PathInput, options?: CpOptions): Promise<void>;
truncate(path: PathInput, len?: number): Promise<void>;
watch(filename: PathInput, options?: WatchOptions | TextEncoding): AsyncIterableIterator<FileChangeInfo>;
readonly constants: FsConstants;
}
Promise-based filesystem API exposed as fs.promises.
| Property | Type | Description | Since |
|---|---|---|---|
constants readonly | FsConstants | Filesystem access and copy mode constants. | v0.0.0-alpha.0 |
FsPromises.readFile
Section titled “FsPromises.readFile”readFile(path: PathInput, options?: { encoding?: null | undefined } | null): Promise<Uint8Array>;
readFile(path: PathInput, options: TextEncoding | { encoding: TextEncoding }): Promise<string>;
Asynchronously read the entire contents of path as bytes.
Asynchronously read the entire contents of path as an encoded string.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
options optional | { encoding?: null | undefined } | null | TextEncoding | { encoding: TextEncoding } | Optional object with encoding: null | undefined (or null); Encoding name or { encoding } object. |
Promise<Uint8Array>— Promise resolving to aBuffer(Uint8Arraysubclass) with the file bytes.Promise<string>— Promise resolving to the decoded string contents.
TypeError— on invalidpathoroptionstypes; on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).Error— withcode"ENOENT","EACCES","EISDIR","EINVAL","ERR_FS_FILE_TOO_LARGE", or"EIO".
FsPromises.writeFile
Section titled “FsPromises.writeFile”writeFile(path: PathInput, data: string | Uint8Array | ArrayBufferView, options?: TextEncoding | { encoding?: TextEncoding | null }): Promise<void>;
Asynchronously write data to path, replacing the file if it already exists.
| Name | Type | Description |
|---|---|---|
path | PathInput | Destination filesystem path or file:// URL. |
data | string | Uint8Array | ArrayBufferView | String or byte view to write. |
options optional | TextEncoding | { encoding?: TextEncoding | null } | Encoding for string data (default "utf8") or options object. |
Promise<void> — Promise resolving when the write completes.TypeError— on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).Error— withcode"ENOENT","EACCES","EISDIR","EINVAL", or"EIO".
FsPromises.appendFile
Section titled “FsPromises.appendFile”appendFile(path: PathInput, data: string | Uint8Array | ArrayBufferView, options?: TextEncoding | { encoding?: TextEncoding | null }): Promise<void>;
Asynchronously append data to path, creating the file if it does not exist.
| Name | Type | Description |
|---|---|---|
path | PathInput | Destination filesystem path or file:// URL. |
data | string | Uint8Array | ArrayBufferView | String or byte view to append. |
options optional | TextEncoding | { encoding?: TextEncoding | null } | Encoding for string data (default "utf8") or options object. |
Promise<void> — Promise resolving when the append completes.TypeError— on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).Error— withcode"ENOENT","EACCES","EISDIR","EINVAL", or"EIO".
FsPromises.stat
Section titled “FsPromises.stat”stat(path: PathInput): Promise<Stats>;
Asynchronously return Stats for path, following symbolic links.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
TypeError— whenpathhas an invalid type.Error— withcode"ENOENT","EACCES","EINVAL", or"EIO".
FsPromises.lstat
Section titled “FsPromises.lstat”lstat(path: PathInput): Promise<Stats>;
Asynchronously return Stats for path, without following symbolic links.
| Name | Type | Description |
|---|---|---|
path | PathInput | Filesystem path or file:// URL. |
TypeError— whenpathhas an invalid type.Error— withcode"ENOENT","EACCES","EINVAL", or"EIO".
FsPromises.readdir
Section titled “FsPromises.readdir”readdir(path: PathInput, options?: { withFileTypes?: false }): Promise<string[]>;
readdir(path: PathInput, options: { withFileTypes: true }): Promise<Dirent[]>;
Asynchronously read directory entry names.
Asynchronously read directory entries as Dirent objects.
| Name | Type | Description |
|---|---|---|
path | PathInput | Directory path or file:// URL. |
options optional | { withFileTypes?: false } | { withFileTypes: true } | Optional { withFileTypes?: false }; { withFileTypes: true }. |
TypeError— whenpathhas an invalid type.Error— withcode"ENOENT","ENOTDIR","EACCES","EINVAL", or"EIO".
FsPromises.mkdir
Section titled “FsPromises.mkdir”mkdir(path: PathInput, options?: { recursive?: boolean }): Promise<void>;
Asynchronously create a directory at path.
| Name | Type | Description |
|---|---|---|
path | PathInput | Directory path or file:// URL. |
options optional | { recursive?: boolean } | Set recursive: true to create missing parent directories and ignore existing directories. |
Promise<void> — Promise resolving when the directory exists.TypeError— whenpathhas an invalid type.Error— withcode"EEXIST","ENOENT","EACCES","EINVAL", or"EIO".
FsPromises.rm
Section titled “FsPromises.rm”rm(path: PathInput, options?: { recursive?: boolean; force?: boolean }): Promise<void>;
Asynchronously remove files and directories at path.
| Name | Type | Description |
|---|---|---|
path | PathInput | Target path or file:// URL. |
options optional | { recursive?: boolean; force?: boolean } | Set recursive: true to delete directories and force: true to ignore missing paths (ENOENT). |
Promise<void> — Promise resolving when removal completes.TypeError— whenpathhas an invalid type.Error— withcode"ENOENT"(unlessforce: true),"EISDIR","ENOTEMPTY","EACCES","EINVAL", or"EIO".
FsPromises.unlink
Section titled “FsPromises.unlink”unlink(path: PathInput): Promise<void>;
Asynchronously remove a file or symbolic link at path.
| Name | Type | Description |
|---|---|---|
path | PathInput | File or symlink path or file:// URL. |
Promise<void> — Promise resolving when the entry is removed.TypeError— whenpathhas an invalid type.Error— withcode"ENOENT","EISDIR","EACCES","EINVAL", or"EIO".
FsPromises.rename
Section titled “FsPromises.rename”rename(oldPath: PathInput, newPath: PathInput): Promise<void>;
Asynchronously rename oldPath to newPath.
| Name | Type | Description |
|---|---|---|
oldPath | PathInput | Existing source path or file:// URL. |
newPath | PathInput | Destination path or file:// URL. |
Promise<void> — Promise resolving when the rename completes.TypeError— whenoldPathornewPathhas an invalid type.Error— withcode"ENOENT","EACCES","EINVAL", or"EIO".
FsPromises.copyFile
Section titled “FsPromises.copyFile”copyFile(src: PathInput, dest: PathInput, mode?: number): Promise<void>;
Asynchronously copy src to dest.
| Name | Type | Description |
|---|---|---|
src | PathInput | Source file path or file:// URL. |
dest | PathInput | Destination file path or file:// URL. |
mode optional | number | Optional bitmask (pass constants.COPYFILE_EXCL to fail with EEXIST if dest exists). |
Promise<void> — Promise resolving when the copy completes.TypeError— whensrcordesthas an invalid type.Error— withcode"ENOENT","EEXIST","EACCES","EINVAL", or"EIO".
FsPromises.realpath
Section titled “FsPromises.realpath”realpath(path: PathInput): Promise<string>;
Asynchronously compute the canonical pathname for path.
| Name | Type | Description |
|---|---|---|
path | PathInput | Path or file:// URL to resolve. |
Promise<string> — Promise resolving to the canonicalized path string.TypeError— whenpathhas an invalid type.Error— withcode"ENOENT","EACCES","EINVAL", or"EIO".
FsPromises.mkdtemp
Section titled “FsPromises.mkdtemp”mkdtemp(prefix: string): Promise<string>;
Asynchronously create a unique temporary directory starting with prefix.
Appends 6 random alphanumeric characters to prefix and creates the
directory (mode 0o700 on Unix). The parent directory must already exist.
| Name | Type | Description |
|---|---|---|
prefix | string | Path prefix for the new temporary directory. |
Promise<string> — Promise resolving to the path of the created directory.TypeError— whenprefixis not a string.Error— withcode"EINVAL"(empty/NUL prefix),"ENOENT","EACCES", or"EIO".
FsPromises.open
Section titled “FsPromises.open”open(path: PathInput, flags?: string | number, mode?: string | number): Promise<FileHandle>;
Asynchronously open path and return a FileHandle.
| Name | Type | Description |
|---|---|---|
path | PathInput | — |
flags optional | string | number | — |
mode optional | string | number | — |
FsPromises.access
Section titled “FsPromises.access”access(path: PathInput, mode?: number): Promise<void>;
Asynchronously test user permissions for path.
| Name | Type | Description |
|---|---|---|
path | PathInput | — |
mode optional | number | — |
Promise<void>FsPromises.symlink
Section titled “FsPromises.symlink”symlink(target: PathInput, path: PathInput, type?: "dir" | "file" | "junction"): Promise<void>;
Asynchronously create a symbolic link at path pointing to target.
| Name | Type | Description |
|---|---|---|
target | PathInput | — |
path | PathInput | — |
type optional | "dir" | "file" | "junction" | — |
Promise<void>FsPromises.readlink
Section titled “FsPromises.readlink”readlink(path: PathInput, options?: TextEncoding | { encoding?: TextEncoding } | null): Promise<string>;
readlink(path: PathInput, options: "buffer" | { encoding: "buffer" }): Promise<Uint8Array>;
Asynchronously read the target of the symbolic link at path.
Asynchronously read the target of the symbolic link at path as bytes.
| Name | Type | Description |
|---|---|---|
path | PathInput | — |
options optional | TextEncoding | { encoding?: TextEncoding } | null | "buffer" | { encoding: "buffer" } | — |
Promise<string>Promise<Uint8Array>
FsPromises.chmod
Section titled “FsPromises.chmod”chmod(path: PathInput, mode: string | number): Promise<void>;
Asynchronously change the permissions of path.
| Name | Type | Description |
|---|---|---|
path | PathInput | — |
mode | string | number | — |
Promise<void>FsPromises.cp
Section titled “FsPromises.cp”cp(src: PathInput, dest: PathInput, options?: CpOptions): Promise<void>;
Asynchronously copy files or directories from src to dest.
Promise<void>FsPromises.truncate
Section titled “FsPromises.truncate”truncate(path: PathInput, len?: number): Promise<void>;
Asynchronously truncate (or extend) the file at path to len bytes.
| Name | Type | Description |
|---|---|---|
path | PathInput | — |
len optional | number | — |
Promise<void>FsPromises.watch
Section titled “FsPromises.watch”watch(filename: PathInput, options?: WatchOptions | TextEncoding): AsyncIterableIterator<FileChangeInfo>;
Asynchronously watch filename for filesystem changes.
| Name | Type | Description |
|---|---|---|
filename | PathInput | — |
options optional | WatchOptions | TextEncoding | — |
Type Aliases
Section titled “Type Aliases”TextEncoding
Section titled “TextEncoding”export type TextEncoding = "utf8" | "utf-8" | "hex" | "base64" | "base64url" | "latin1" | "ascii";
Supported text encodings for filesystem string operations.
PathInput
Section titled “PathInput”export type PathInput = string | { readonly href: string; readonly protocol: string };
Filesystem path string or file:// URL-like object.
WatchListener
Section titled “WatchListener”export type WatchListener = (eventType: "rename" | "change", filename: string | null) => void;
Listener callback invoked by fs.watch().
Constants
Section titled “Constants”constants
Section titled “constants”export const constants: FsConstants;
Filesystem access and copy mode constants.
promises
Section titled “promises”export const promises: FsPromises;
Promise-based filesystem API (node:fs/promises).
Default Export
Section titled “Default Export”default export
Section titled “default export”const _default: {
/** Synchronously read file contents. @since 0.0.0-alpha.0 */
readFileSync: typeof readFileSync;
/** Synchronously write file contents. @since 0.0.0-alpha.0 */
writeFileSync: typeof writeFileSync;
/** Synchronously append file contents. @since 0.0.0-alpha.0 */
appendFileSync: typeof appendFileSync;
/** Synchronously test whether a path exists. @since 0.0.0-alpha.0 */
existsSync: typeof existsSync;
/** Synchronously stat a path, following symlinks. @since 0.0.0-alpha.0 */
statSync: typeof statSync;
/** Synchronously stat a path without following symlinks. @since 0.0.0-alpha.0 */
lstatSync: typeof lstatSync;
/** Synchronously read directory entries. @since 0.0.0-alpha.0 */
readdirSync: typeof readdirSync;
/** Synchronously create a directory. @since 0.0.0-alpha.0 */
mkdirSync: typeof mkdirSync;
/** Synchronously remove files or directories. @since 0.0.0-alpha.0 */
rmSync: typeof rmSync;
/** Synchronously remove a file or symlink. @since 0.0.0-alpha.0 */
unlinkSync: typeof unlinkSync;
/** Synchronously rename a file or directory. @since 0.0.0-alpha.0 */
renameSync: typeof renameSync;
/** Synchronously copy a file. @since 0.0.0-alpha.0 */
copyFileSync: typeof copyFileSync;
/** Synchronously canonicalize a path. @since 0.0.0-alpha.0 */
realpathSync: typeof realpathSync;
/** Synchronously create a unique temporary directory. @since 0.0.0-alpha.0 */
mkdtempSync: typeof mkdtempSync;
/** Synchronously open a file descriptor. @since 0.0.0-alpha.2 */
openSync: typeof openSync;
/** Synchronously read from a file descriptor. @since 0.0.0-alpha.2 */
readSync: typeof readSync;
/** Synchronously write to a file descriptor. @since 0.0.0-alpha.2 */
writeSync: typeof writeSync;
/** Synchronously close a file descriptor. @since 0.0.0-alpha.2 */
closeSync: typeof closeSync;
/** Synchronously stat an open file descriptor. @since 0.0.0-alpha.2 */
fstatSync: typeof fstatSync;
/** Synchronously flush a file descriptor to disk. @since 0.0.0-alpha.2 */
fsyncSync: typeof fsyncSync;
/** Synchronously truncate an open file descriptor. @since 0.0.0-alpha.2 */
ftruncateSync: typeof ftruncateSync;
/** Synchronously truncate a file path. @since 0.0.0-alpha.2 */
truncateSync: typeof truncateSync;
/** Synchronously test file accessibility. @since 0.0.0-alpha.2 */
accessSync: typeof accessSync;
/** Synchronously create a symbolic link. @since 0.0.0-alpha.2 */
symlinkSync: typeof symlinkSync;
/** Synchronously read a symbolic link target. @since 0.0.0-alpha.2 */
readlinkSync: typeof readlinkSync;
/** Synchronously change file permissions. @since 0.0.0-alpha.2 */
chmodSync: typeof chmodSync;
/** Synchronously copy files or directories. @since 0.0.0-alpha.2 */
cpSync: typeof cpSync;
/** Open a readable file stream. @since 0.0.0-alpha.2 */
createReadStream: typeof createReadStream;
/** Open a writable file stream. @since 0.0.0-alpha.2 */
createWriteStream: typeof createWriteStream;
/** Watch a file or directory for changes. @since 0.0.0-alpha.2 */
watch: typeof watch;
/** Filesystem access and copy mode constants. @since 0.0.0-alpha.0 */
readonly constants: FsConstants;
/** Promise-based filesystem API (`node:fs/promises`). @since 0.0.0-alpha.0 */
readonly promises: FsPromises;
};
export default _default;
createReadStream, createWriteStream, watch, promises are available in vjs (V8) only and omitted from the default export in vjs-lite.Default export object providing all node:fs functions, constants, and promises.
