Skip to content
VaelJS Blog

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"
Since v0.0.0-alpha.0 vjs (V8) vjs-lite (QuickJS)
Cargo feature: 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.
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 });
API Symbols
Functions (30)
readFileSyncv0.0.0-alpha.0
Synchronously read the entire contents of path as bytes.
writeFileSyncv0.0.0-alpha.0
Synchronously write data to path, replacing the file if it already exists.
appendFileSyncv0.0.0-alpha.0
Synchronously append data to path, creating the file if it does not exist.
existsSyncv0.0.0-alpha.0
Synchronously return true if path exists.
statSyncv0.0.0-alpha.0
Synchronously return Stats for path, following symbolic links.
lstatSyncv0.0.0-alpha.0
Synchronously return Stats for path, without following symbolic links.
readdirSyncv0.0.0-alpha.0
Synchronously read directory entry names.
mkdirSyncv0.0.0-alpha.0
Synchronously create a directory at path.
rmSyncv0.0.0-alpha.0
Synchronously remove files and directories at path.
unlinkSyncv0.0.0-alpha.0
Synchronously remove a file or symbolic link at path.
renameSyncv0.0.0-alpha.0
Synchronously rename oldPath to newPath.
copyFileSyncv0.0.0-alpha.0
Synchronously copy src to dest.
realpathSyncv0.0.0-alpha.0
Synchronously compute the canonical pathname for path.
mkdtempSyncv0.0.0-alpha.0
Synchronously create a unique temporary directory starting with prefix.
openSyncv0.0.0-alpha.2
Synchronously open path and return a numeric file descriptor.
readSyncv0.0.0-alpha.2
Synchronously read bytes from file descriptor fd into buffer.
writeSyncv0.0.0-alpha.2
Synchronously write bytes from buffer to file descriptor fd.
closeSyncv0.0.0-alpha.2
Synchronously close an open file descriptor fd.
fstatSyncv0.0.0-alpha.2
Synchronously return Stats for open file descriptor fd.
fsyncSyncv0.0.0-alpha.2
Synchronously flush all modified file data and metadata for fd to storage.
ftruncateSyncv0.0.0-alpha.2
Synchronously truncate (or extend) the file referenced by fd to len bytes.
truncateSyncv0.0.0-alpha.2
Synchronously truncate (or extend) the file at path to len bytes.
accessSyncv0.0.0-alpha.2
Synchronously test user permissions for path, throwing if inaccessible.
symlinkSyncv0.0.0-alpha.2
Synchronously create a symbolic link at path pointing to target.
readlinkSyncv0.0.0-alpha.2
Synchronously read the target of the symbolic link at path as a string.
chmodSyncv0.0.0-alpha.2
Synchronously change the permissions of path.
cpSyncv0.0.0-alpha.2
Synchronously copy files or directories from src to dest.
createReadStreamvjs onlyv0.0.0-alpha.2
Open a readable stream for path.
createWriteStreamvjs onlyv0.0.0-alpha.2
Open a writable stream for path.
watchvjs onlyv0.0.0-alpha.2
Watch filename (file or directory) for changes.
functionSince v0.0.0-alpha.0vjs & vjs-lite
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.

Parameters
NameTypeDescription
pathPathInputFilesystem 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.
Returns
  • Uint8Array — Buffer (Uint8Array subclass) containing the file bytes.
  • string — Decoded string contents of the file.
Exceptions
  • TypeError — on invalid path or options types; on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).
  • Error — with code "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);
functionSince v0.0.0-alpha.0vjs & vjs-lite
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.

Parameters
NameTypeDescription
pathPathInputDestination filesystem path or file:// URL.
datastring | Uint8Array | ArrayBufferViewString or byte view to write.
options optionalTextEncoding | { encoding?: TextEncoding | null }Encoding for string data (default "utf8") or options object.
Returns
void
Exceptions
  • TypeError — on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).
  • Error — with code "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"));
functionSince v0.0.0-alpha.0vjs & vjs-lite
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.

Parameters
NameTypeDescription
pathPathInputDestination filesystem path or file:// URL.
datastring | Uint8Array | ArrayBufferViewString or byte view to append.
options optionalTextEncoding | { encoding?: TextEncoding | null }Encoding for string data (default "utf8") or options object.
Returns
void
Exceptions
  • TypeError — on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).
  • Error — with code "ENOENT", "EACCES", "EISDIR", "EINVAL", or "EIO".
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function existsSync(path: PathInput): boolean;

Synchronously return true if path exists.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
Returns
boolean — true if path exists, otherwise false.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code = "EINVAL" if path is invalid (for example, contains a NUL byte).
import { existsSync } from "node:fs";
console.log(existsSync("/tmp"));
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function statSync(path: PathInput): Stats;

Synchronously return Stats for path, following symbolic links.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
Returns
Stats — Stats metadata for the resolved entry.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "EACCES", "EINVAL", or "EIO".
import { statSync } from "node:fs";
const info = statSync("/tmp");
console.log(info.isDirectory(), info.size);
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function lstatSync(path: PathInput): Stats;

Synchronously return Stats for path, without following symbolic links.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
Returns
Stats — Stats metadata for the entry itself (including symlinks).
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "EACCES", "EINVAL", or "EIO".
functionSince v0.0.0-alpha.0vjs & vjs-lite
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.

Parameters
NameTypeDescription
pathPathInputDirectory path or file:// URL.
options optional{ withFileTypes?: false } | { withFileTypes: true }Optional { withFileTypes?: false }; { withFileTypes: true }.
Returns
  • string[] — Array of entry names inside path.
  • Dirent[] — Array of Dirent objects inside path.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "ENOTDIR", "EACCES", "EINVAL", or "EIO".
import { readdirSync } from "node:fs";
const entries = readdirSync("/tmp");
console.log(entries.length);
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function mkdirSync(path: PathInput, options?: { recursive?: boolean }): void;

Synchronously create a directory at path.

Parameters
NameTypeDescription
pathPathInputDirectory path or file:// URL.
options optional{ recursive?: boolean }Set recursive: true to create missing parent directories and succeed if already present.
Returns
void
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "EEXIST", "ENOENT", "EACCES", "EINVAL", or "EIO".
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function rmSync(path: PathInput, options?: { recursive?: boolean; force?: boolean }): void;

Synchronously remove files and directories at path.

Parameters
NameTypeDescription
pathPathInputTarget 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).
Returns
void
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT" (unless force: true), "EISDIR", "ENOTEMPTY", "EACCES", "EINVAL", or "EIO".
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function unlinkSync(path: PathInput): void;

Synchronously remove a file or symbolic link at path.

Parameters
NameTypeDescription
pathPathInputFile or symlink path or file:// URL.
Returns
void
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "EISDIR", "EACCES", "EINVAL", or "EIO".
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function renameSync(oldPath: PathInput, newPath: PathInput): void;

Synchronously rename oldPath to newPath.

Parameters
NameTypeDescription
oldPathPathInputExisting source path or file:// URL.
newPathPathInputDestination path or file:// URL.
Returns
void
Exceptions
  • TypeError — when oldPath or newPath has an invalid type.
  • Error — with code "ENOENT", "EACCES", "EINVAL", or "EIO".
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function copyFileSync(src: PathInput, dest: PathInput, mode?: number): void;

Synchronously copy src to dest.

Parameters
NameTypeDescription
srcPathInputSource file path or file:// URL.
destPathInputDestination file path or file:// URL.
mode optionalnumberOptional bitmask (pass constants.COPYFILE_EXCL to fail with EEXIST if dest exists).
Returns
void
Exceptions
  • TypeError — when src or dest has an invalid type.
  • Error — with code "ENOENT", "EEXIST", "EACCES", "EINVAL", or "EIO".
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function realpathSync(path: PathInput): string;

Synchronously compute the canonical pathname for path.

Parameters
NameTypeDescription
pathPathInputPath or file:// URL to canonicalize.
Returns
string — Resolved canonical path string.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "EACCES", "EINVAL", or "EIO".
functionSince v0.0.0-alpha.0vjs & vjs-lite
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.

Parameters
NameTypeDescription
prefixstringPath prefix for the new temporary directory.
Returns
string — Path of the created temporary directory.
Exceptions
  • TypeError — when prefix is not a string.
  • Error — with code "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 });
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function openSync(
  path: PathInput,
  flags?: string | number,
  mode?: string | number,
): number;

Synchronously open path and return a numeric file descriptor.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
flags optionalstring | numberOpen flags string or numeric bitmask (default "r").
mode optionalstring | numberPOSIX file permissions when creating a file (default 0o666).
Returns
number — Numeric file descriptor.
functionSince v0.0.0-alpha.2vjs & vjs-lite
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.

Overload 1 — readSync(fd, buffer, offset?, length?, position?)
NameTypeDescription
fdnumberOpen file descriptor returned by openSync.
bufferArrayBufferViewDestination ArrayBufferView.
offset optionalnumberByte offset in buffer to start writing (default 0).
length optionalnumberNumber of bytes to read.
position optionalnumber | nullFile position to read from (null uses current offset).
number — Number of bytes read (0 at EOF).
Overload 2 — readSync(fd, buffer, options?)

Synchronously read bytes from file descriptor fd into buffer using options.

NameTypeDescription
fdnumberOpen file descriptor returned by openSync.
bufferArrayBufferViewDestination ArrayBufferView.
options optionalReadSyncOptionsRead offset, length, and position options.
number — Number of bytes read (0 at EOF).
functionSince v0.0.0-alpha.2vjs & vjs-lite
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.

Overload 1 — writeSync(fd, buffer, offset?, length?, position?)
NameTypeDescription
fdnumberOpen file descriptor returned by openSync.
bufferArrayBufferViewSource ArrayBufferView.
offset optionalnumberByte offset in buffer to start reading (default 0).
length optionalnumberNumber of bytes to write.
position optionalnumber | nullFile position to write at (null uses current offset).
number — Number of bytes written.
Overload 2 — writeSync(fd, data, position?, encoding?)

Synchronously write string data to file descriptor fd.

NameTypeDescription
fdnumberOpen file descriptor returned by openSync.
datastringString to write.
position optionalnumber | nullFile position to write at (null uses current offset).
encoding optionalTextEncodingCharacter encoding for data (default "utf8").
number — Number of bytes written.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function closeSync(fd: number): void;

Synchronously close an open file descriptor fd.

Parameters
NameTypeDescription
fdnumberOpen file descriptor returned by openSync.
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function fstatSync(fd: number): Stats;

Synchronously return Stats for open file descriptor fd.

Parameters
NameTypeDescription
fdnumberOpen file descriptor returned by openSync.
Returns
Stats — Stats metadata for fd.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function fsyncSync(fd: number): void;

Synchronously flush all modified file data and metadata for fd to storage.

Parameters
NameTypeDescription
fdnumberOpen file descriptor returned by openSync.
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function ftruncateSync(fd: number, len?: number): void;

Synchronously truncate (or extend) the file referenced by fd to len bytes.

Parameters
NameTypeDescription
fdnumberOpen file descriptor returned by openSync.
len optionalnumberTarget byte length (default 0).
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function truncateSync(path: PathInput, len?: number): void;

Synchronously truncate (or extend) the file at path to len bytes.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
len optionalnumberTarget byte length (default 0).
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function accessSync(path: PathInput, mode?: number): void;

Synchronously test user permissions for path, throwing if inaccessible.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
mode optionalnumberOptional accessibility bitmask (F_OK, R_OK, W_OK, X_OK, default F_OK).
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function symlinkSync(
  target: PathInput,
  path: PathInput,
  type?: "dir" | "file" | "junction",
): void;

Synchronously create a symbolic link at path pointing to target.

Parameters
NameTypeDescription
targetPathInputLink target path.
pathPathInputSymbolic link path to create.
type optional"dir" | "file" | "junction"Optional Windows symlink hint ("dir", "file", or "junction").
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
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.

Parameters
NameTypeDescription
pathPathInputSymbolic link path or file:// URL.
options optionalTextEncoding | { encoding?: TextEncoding } | null | "buffer" | { encoding: "buffer" }Optional encoding ("utf8" default); { encoding: "buffer" }.
Returns
  • string — Symlink target string.
  • Uint8Array — Symlink target as Uint8Array.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function chmodSync(path: PathInput, mode: string | number): void;

Synchronously change the permissions of path.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
modestring | numberNumeric or octal string file mode.
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function cpSync(src: PathInput, dest: PathInput, options?: CpOptions): void;

Synchronously copy files or directories from src to dest.

Parameters
NameTypeDescription
srcPathInputSource file or directory path.
destPathInputDestination path.
options optionalCpOptionsOptional copy behavior (recursive, force, filter, etc.).
Returns
void
functionSince v0.0.0-alpha.2vjs only
export function createReadStream(
  path: PathInput,
  options?: TextEncoding | ReadStreamOptions,
): ReadStream;

Open a readable stream for path.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
options optionalTextEncoding | ReadStreamOptionsOptional encoding or stream options.
Returns
ReadStream — ReadStream instance.
functionSince v0.0.0-alpha.2vjs only
export function createWriteStream(
  path: PathInput,
  options?: TextEncoding | WriteStreamOptions,
): WriteStream;

Open a writable stream for path.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
options optionalTextEncoding | WriteStreamOptionsOptional encoding or stream options.
Returns
WriteStream — WriteStream instance.
functionSince v0.0.0-alpha.2vjs only
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.

Overload 1 — watch(filename, options?, listener?)
NameTypeDescription
filenamePathInputFilesystem path or file:// URL to watch.
options optionalWatchOptions | TextEncodingOptional watch settings or encoding string.
listener optionalWatchListenerOptional listener invoked on "change" events.
FSWatcher — FSWatcher handle.
Overload 2 — watch(filename, listener)

Watch filename (file or directory) for changes with a trailing listener.

NameTypeDescription
filenamePathInputFilesystem path or file:// URL to watch.
listenerWatchListenerListener invoked on "change" events.
FSWatcher — FSWatcher handle.
interfaceSince v0.0.0-alpha.0vjs & vjs-lite
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.

Properties
PropertyTypeDescriptionSince
size readonlynumberSize of the file in bytes.v0.0.0-alpha.0
mode readonlynumberPOSIX file type and permissions bitmask.v0.0.0-alpha.2
atimeMs readonlynumberLast access timestamp in milliseconds since the Unix epoch.v0.0.0-alpha.2
atime readonlyDateLast access timestamp as a Date instance.v0.0.0-alpha.2
mtimeMs readonlynumberLast modification timestamp in milliseconds since the Unix epoch.v0.0.0-alpha.0
mtime readonlyDateLast modification timestamp as a Date instance.v0.0.0-alpha.0
ctimeMs readonlynumberLast status change timestamp in milliseconds since the Unix epoch.v0.0.0-alpha.2
ctime readonlyDateLast status change timestamp as a Date instance.v0.0.0-alpha.2
birthtimeMs readonlynumberFile creation (birthtime) timestamp in milliseconds since the Unix epoch.v0.0.0-alpha.2
birthtime readonlyDateFile creation (birthtime) timestamp as a Date instance.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.0
isFile(): boolean;

Return true if the entry is a regular file.

Returns
boolean — true for a regular file, otherwise false.
methodSince v0.0.0-alpha.0
isDirectory(): boolean;

Return true if the entry is a directory.

Returns
boolean — true for a directory, otherwise false.
methodSince v0.0.0-alpha.0
isSymbolicLink(): boolean;

Return true if the entry is a symbolic link.

Returns
boolean — true for a symbolic link, otherwise false.
methodSince v0.0.0-alpha.2
isFIFO(): boolean;

Return true if the entry is a FIFO (named pipe).

Returns
boolean — true for a FIFO, otherwise false.
methodSince v0.0.0-alpha.2
isSocket(): boolean;

Return true if the entry is a socket.

Returns
boolean — true for a socket, otherwise false.
methodSince v0.0.0-alpha.2
isBlockDevice(): boolean;

Return true if the entry is a block device.

Returns
boolean — true for a block device, otherwise false.
methodSince v0.0.0-alpha.2
isCharacterDevice(): boolean;

Return true if the entry is a character device.

Returns
boolean — true for a character device, otherwise false.
interfaceSince v0.0.0-alpha.0vjs & vjs-lite
export interface Dirent {
  readonly name: string;
  readonly parentPath: string;
  isFile(): boolean;
  isDirectory(): boolean;
  isSymbolicLink(): boolean;
}

Directory entry returned by readdirSync / readdir with withFileTypes: true.

Properties
PropertyTypeDescriptionSince
name readonlystringEntry filename relative to the directory passed to readdirSync / readdir.v0.0.0-alpha.0
parentPath readonlystringPath to the parent directory containing this entry.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.0
isFile(): boolean;

Return true if the entry is a regular file.

Returns
boolean — true for a regular file, otherwise false.
methodSince v0.0.0-alpha.0
isDirectory(): boolean;

Return true if the entry is a directory.

Returns
boolean — true for a directory, otherwise false.
methodSince v0.0.0-alpha.0
isSymbolicLink(): boolean;

Return true if the entry is a symbolic link.

Returns
boolean — true for a symbolic link, otherwise false.
interfaceSince v0.0.0-alpha.0vjs & vjs-lite
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.

Properties
PropertyTypeDescriptionSince
F_OK readonlynumberFlag testing existence of the path (0).v0.0.0-alpha.0
R_OK readonlynumberFlag testing read permission (4).v0.0.0-alpha.0
W_OK readonlynumberFlag testing write permission (2).v0.0.0-alpha.0
X_OK readonlynumberFlag testing execute permission (1).v0.0.0-alpha.0
COPYFILE_EXCL readonlynumberCopy flag failing if the destination file already exists (1).v0.0.0-alpha.0
COPYFILE_FICLONE readonlynumberCopy flag requesting copy-on-write reflink if supported (2).v0.0.0-alpha.0
COPYFILE_FICLONE_FORCE readonlynumberCopy flag requiring copy-on-write reflink (4).v0.0.0-alpha.0
interfaceSince v0.0.0-alpha.2vjs only
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().

Properties
PropertyTypeDescriptionSince
aborted readonlybooleanWhether the signal has already been aborted.v0.0.0-alpha.2
reason readonly optionalunknownOptional abort reason value.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
addEventListener(type: string, listener: (...args: any[]) => void, options?: { once?: boolean }): void;

Register an "abort" listener.

Parameters
NameTypeDescription
typestringEvent type ("abort").
listener(...args: any[]) => voidCallback invoked on abort.
options optional{ once?: boolean }Optional listener options.
Returns
void
methodSince v0.0.0-alpha.2
removeEventListener?(type: string, listener: (...args: any[]) => void): void;

Unregister an "abort" listener.

Parameters
NameTypeDescription
typestringEvent type ("abort").
listener(...args: any[]) => voidCallback to remove.
Returns
void
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface ReadSyncOptions {
  offset?: number;
  length?: number;
  position?: number | null;
}

Options accepted by readSync().

Properties
PropertyTypeDescriptionSince
offset optionalnumberByte offset within buffer to start writing (default 0).v0.0.0-alpha.2
length optionalnumberMaximum number of bytes to read (default buffer.byteLength - offset).v0.0.0-alpha.2
position optionalnumber | nullFile position to read from (null uses current file offset).v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
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().

Properties
PropertyTypeDescriptionSince
dereference optionalbooleanDereference symbolic links during copy.v0.0.0-alpha.2
errorOnExist optionalbooleanThrow 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 optionalbooleanOverwrite existing files (default true).v0.0.0-alpha.2
recursive optionalbooleanCopy directories recursively (default false).v0.0.0-alpha.2
preserveTimestamps optionalbooleanPreserve file timestamps when true.v0.0.0-alpha.2
verbatimSymlinks optionalbooleanPreserve symlink behavior without following links.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
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().

Properties
PropertyTypeDescriptionSince
flags optionalstringOpen flags string (default "r").v0.0.0-alpha.2
encoding optionalTextEncoding | nullOutput string encoding (null for raw Buffer).v0.0.0-alpha.2
fd optionalnumberExisting open file descriptor to wrap instead of opening path.v0.0.0-alpha.2
mode optionalnumberFile mode if creating a file (default 0o666).v0.0.0-alpha.2
autoClose optionalbooleanAutomatically close the file descriptor on end/error (default true).v0.0.0-alpha.2
emitClose optionalbooleanEmit "close" after stream destruction (default true).v0.0.0-alpha.2
start optionalnumberStarting byte offset in the file (inclusive).v0.0.0-alpha.2
end optionalnumberEnding byte offset in the file (inclusive).v0.0.0-alpha.2
highWaterMark optionalnumberInternal read chunk size in bytes (default 65536).v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
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().

Properties
PropertyTypeDescriptionSince
flags optionalstringOpen flags string (default "w").v0.0.0-alpha.2
encoding optionalTextEncodingDefault encoding for written strings (default "utf8").v0.0.0-alpha.2
fd optionalnumberExisting open file descriptor to wrap instead of opening path.v0.0.0-alpha.2
mode optionalnumberPOSIX file mode when creating a file (default 0o666).v0.0.0-alpha.2
autoClose optionalbooleanAutomatically close the file descriptor on finish/error (default true).v0.0.0-alpha.2
emitClose optionalbooleanEmit "close" after stream destruction (default true).v0.0.0-alpha.2
start optionalnumberStarting byte offset in the file.v0.0.0-alpha.2
highWaterMark optionalnumberInternal write buffer high-water mark in bytes.v0.0.0-alpha.2
flush optionalbooleanFlush file data to storage before closing.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
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().

Properties
PropertyTypeDescriptionSince
bytesRead readonlynumberTotal bytes read from the file so far.v0.0.0-alpha.2
path readonlystring | Uint8ArrayPath passed to createReadStream().v0.0.0-alpha.2
pending readonlybooleanWhether the stream is currently waiting for the file to open.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
on(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
once(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a one-time stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
off(eventName: string | symbol, listener: (...args: any[]) => void): this;

Remove a stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
pause(): this;

Pause "data" events.

Returns
this
methodSince v0.0.0-alpha.2
resume(): this;

Resume "data" events.

Returns
this
methodSince v0.0.0-alpha.2
pipe<T extends { write(chunk: any, ...args: any[]): any; end(...args: any[]): any }>(
  destination: T,
  options?: { end?: boolean },
): T;

Pipe stream chunks into destination.

Parameters
NameTypeDescription
destinationT—
options optional{ end?: boolean }—
Returns
T
methodSince v0.0.0-alpha.2
close(callback?: (err?: Error | null) => void): void;

Close and destroy the stream.

Parameters
NameTypeDescription
callback optional(err?: Error | null) => void—
Returns
void
methodSince v0.0.0-alpha.2
destroy(error?: Error): this;

Destroy the stream.

Parameters
NameTypeDescription
error optionalError—
Returns
this
methodSince v0.0.0-alpha.2
[Symbol.asyncIterator](): AsyncIterableIterator<any>;

Iterate asynchronously over file chunks.

interfaceSince v0.0.0-alpha.2vjs only
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().

Properties
PropertyTypeDescriptionSince
bytesWritten readonlynumberTotal bytes written to the file so far.v0.0.0-alpha.2
path readonlystring | Uint8ArrayPath passed to createWriteStream().v0.0.0-alpha.2
pending readonlybooleanWhether the stream is currently waiting for the file to open.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
on(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
once(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a one-time stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
off(eventName: string | symbol, listener: (...args: any[]) => void): this;

Remove a stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
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.

Overload 1 — write(chunk, callback?)
NameTypeDescription
chunkstring | Uint8Array | ArrayBufferView—
callback optional(err?: Error | null) => void—
boolean
Overload 2 — write(chunk, encoding, callback?)

Write a string chunk with explicit encoding to the file.

NameTypeDescription
chunkstring—
encodingTextEncoding—
callback optional(err?: Error | null) => void—
boolean
methodSince v0.0.0-alpha.2
end(callback?: () => void): this;
end(chunk: string | Uint8Array | ArrayBufferView, callback?: () => void): this;

Finish writing and close the file stream.

Overload 1 — end(callback?)
NameTypeDescription
callback optional() => void—
this
Overload 2 — end(chunk, callback?)

Write a final chunk and close the file stream.

NameTypeDescription
chunkstring | Uint8Array | ArrayBufferView—
callback optional() => void—
this
methodSince v0.0.0-alpha.2
close(callback?: (err?: Error | null) => void): void;

Close and destroy the stream.

Parameters
NameTypeDescription
callback optional(err?: Error | null) => void—
Returns
void
methodSince v0.0.0-alpha.2
destroy(error?: Error): this;

Destroy the stream.

Parameters
NameTypeDescription
error optionalError—
Returns
this
interfaceSince v0.0.0-alpha.2vjs only
export interface WatchOptions {
  persistent?: boolean;
  recursive?: boolean;
  encoding?: TextEncoding | "buffer";
  signal?: AbortSignalLike;
}

Options accepted by watch().

Properties
PropertyTypeDescriptionSince
persistent optionalbooleanKeep the event loop active while watching (default true).v0.0.0-alpha.2
recursive optionalbooleanWatch subdirectories recursively when true.v0.0.0-alpha.2
encoding optionalTextEncoding | "buffer"Character encoding for emitted filename strings.v0.0.0-alpha.2
signal optionalAbortSignalLikeOptional abort signal stopping the watcher.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
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().

Methods
methodSince v0.0.0-alpha.2
on(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a watcher event listener ("change", "error", "close").

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
once(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a one-time watcher event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
off(eventName: string | symbol, listener: (...args: any[]) => void): this;

Remove a watcher event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
close(): void;

Stop watching for filesystem changes.

Returns
void
methodSince v0.0.0-alpha.2
ref(): this;

Keep the event loop active while watching.

Returns
this
methodSince v0.0.0-alpha.2
unref(): this;

Allow the event loop to exit while watching.

Returns
this
interfaceSince v0.0.0-alpha.2vjs only
export interface FileChangeInfo {
  eventType: "rename" | "change";
  filename: string | null;
}

Change event object yielded by fs.promises.watch().

Properties
PropertyTypeDescriptionSince
eventType "rename" | "change"Filesystem change event kind ("rename" or "change").v0.0.0-alpha.2
filename string | nullChanged filename relative to the watched path, or null.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs only
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().

Properties
PropertyTypeDescriptionSince
fd readonlynumberUnderlying numeric file descriptor.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
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.

Parameters
NameTypeDescription
bufferT—
offset optionalnumber | null—
length optionalnumber | null—
position optionalnumber | null—
Returns
Promise<{ bytesRead: number; buffer: T }>
methodSince v0.0.0-alpha.2
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.

Overload 1 — write(buffer, offset?, length?, position?)
NameTypeDescription
bufferT—
offset optionalnumber | null—
length optionalnumber | null—
position optionalnumber | null—
Promise<{ bytesWritten: number; buffer: T }>
Overload 2 — write(data, position?, encoding?)

Write string data to the file handle.

NameTypeDescription
datastring—
position optionalnumber | null—
encoding optionalTextEncoding—
Promise<{ bytesWritten: number; buffer: string }>
methodSince v0.0.0-alpha.2
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.

Parameters
NameTypeDescription
options optional{ encoding?: null | undefined } | null | TextEncoding | { encoding: TextEncoding }—
Returns
methodSince v0.0.0-alpha.2
writeFile(
  data: string | Uint8Array | ArrayBufferView,
  options?: TextEncoding | { encoding?: TextEncoding | null },
): Promise<void>;

Write data to the file handle.

Parameters
NameTypeDescription
datastring | Uint8Array | ArrayBufferView—
options optionalTextEncoding | { encoding?: TextEncoding | null }—
Returns
Promise<void>
methodSince v0.0.0-alpha.2
appendFile(
  data: string | Uint8Array | ArrayBufferView,
  options?: TextEncoding | { encoding?: TextEncoding | null },
): Promise<void>;

Append data to the file handle.

Parameters
NameTypeDescription
datastring | Uint8Array | ArrayBufferView—
options optionalTextEncoding | { encoding?: TextEncoding | null }—
Returns
Promise<void>
methodSince v0.0.0-alpha.2
stat(): Promise<Stats>;

Return Stats for the open file handle.

Returns
methodSince v0.0.0-alpha.2
sync(): Promise<void>;

Flush modified file data and metadata to disk.

Returns
Promise<void>
methodSince v0.0.0-alpha.2
datasync(): Promise<void>;

Flush modified file data (without metadata) to disk.

Returns
Promise<void>
methodSince v0.0.0-alpha.2
truncate(len?: number): Promise<void>;

Truncate or extend the file to len bytes (default 0).

Parameters
NameTypeDescription
len optionalnumber—
Returns
Promise<void>
methodSince v0.0.0-alpha.2
chmod(mode: string | number): Promise<void>;

Change file permissions on the open handle.

Parameters
NameTypeDescription
modestring | number—
Returns
Promise<void>
methodSince v0.0.0-alpha.2
close(): Promise<void>;

Close the file handle.

Returns
Promise<void>
methodSince v0.0.0-alpha.2
[Symbol.asyncDispose](): Promise<void>;

Close the file handle automatically on await using.

Returns
Promise<void>
interfaceSince v0.0.0-alpha.0vjs only
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.

Properties
PropertyTypeDescriptionSince
constants readonlyFsConstantsFilesystem access and copy mode constants.v0.0.0-alpha.0
Methods
methodSince v0.0.0-alpha.0
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.

Parameters
NameTypeDescription
pathPathInputFilesystem 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.
Returns
  • Promise<Uint8Array> — Promise resolving to a Buffer (Uint8Array subclass) with the file bytes.
  • Promise<string> — Promise resolving to the decoded string contents.
Exceptions
  • TypeError — on invalid path or options types; on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).
  • Error — with code "ENOENT", "EACCES", "EISDIR", "EINVAL", "ERR_FS_FILE_TOO_LARGE", or "EIO".
methodSince v0.0.0-alpha.0
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.

Parameters
NameTypeDescription
pathPathInputDestination filesystem path or file:// URL.
datastring | Uint8Array | ArrayBufferViewString or byte view to write.
options optionalTextEncoding | { encoding?: TextEncoding | null }Encoding for string data (default "utf8") or options object.
Returns
Promise<void> — Promise resolving when the write completes.
Exceptions
  • TypeError — on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).
  • Error — with code "ENOENT", "EACCES", "EISDIR", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
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.

Parameters
NameTypeDescription
pathPathInputDestination filesystem path or file:// URL.
datastring | Uint8Array | ArrayBufferViewString or byte view to append.
options optionalTextEncoding | { encoding?: TextEncoding | null }Encoding for string data (default "utf8") or options object.
Returns
Promise<void> — Promise resolving when the append completes.
Exceptions
  • TypeError — on invalid argument types or unknown encoding (ERR_UNKNOWN_ENCODING).
  • Error — with code "ENOENT", "EACCES", "EISDIR", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
stat(path: PathInput): Promise<Stats>;

Asynchronously return Stats for path, following symbolic links.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
Returns
Promise<Stats> — Promise resolving to Stats for the resolved target.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "EACCES", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
lstat(path: PathInput): Promise<Stats>;

Asynchronously return Stats for path, without following symbolic links.

Parameters
NameTypeDescription
pathPathInputFilesystem path or file:// URL.
Returns
Promise<Stats> — Promise resolving to Stats for the entry itself.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "EACCES", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
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.

Parameters
NameTypeDescription
pathPathInputDirectory path or file:// URL.
options optional{ withFileTypes?: false } | { withFileTypes: true }Optional { withFileTypes?: false }; { withFileTypes: true }.
Returns
  • Promise<string[]> — Promise resolving to an array of entry name strings.
  • Promise<Dirent[]> — Promise resolving to an array of Dirent entries.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "ENOTDIR", "EACCES", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
mkdir(path: PathInput, options?: { recursive?: boolean }): Promise<void>;

Asynchronously create a directory at path.

Parameters
NameTypeDescription
pathPathInputDirectory path or file:// URL.
options optional{ recursive?: boolean }Set recursive: true to create missing parent directories and ignore existing directories.
Returns
Promise<void> — Promise resolving when the directory exists.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "EEXIST", "ENOENT", "EACCES", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
rm(path: PathInput, options?: { recursive?: boolean; force?: boolean }): Promise<void>;

Asynchronously remove files and directories at path.

Parameters
NameTypeDescription
pathPathInputTarget path or file:// URL.
options optional{ recursive?: boolean; force?: boolean }Set recursive: true to delete directories and force: true to ignore missing paths (ENOENT).
Returns
Promise<void> — Promise resolving when removal completes.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT" (unless force: true), "EISDIR", "ENOTEMPTY", "EACCES", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
unlink(path: PathInput): Promise<void>;

Asynchronously remove a file or symbolic link at path.

Parameters
NameTypeDescription
pathPathInputFile or symlink path or file:// URL.
Returns
Promise<void> — Promise resolving when the entry is removed.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "EISDIR", "EACCES", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
rename(oldPath: PathInput, newPath: PathInput): Promise<void>;

Asynchronously rename oldPath to newPath.

Parameters
NameTypeDescription
oldPathPathInputExisting source path or file:// URL.
newPathPathInputDestination path or file:// URL.
Returns
Promise<void> — Promise resolving when the rename completes.
Exceptions
  • TypeError — when oldPath or newPath has an invalid type.
  • Error — with code "ENOENT", "EACCES", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
copyFile(src: PathInput, dest: PathInput, mode?: number): Promise<void>;

Asynchronously copy src to dest.

Parameters
NameTypeDescription
srcPathInputSource file path or file:// URL.
destPathInputDestination file path or file:// URL.
mode optionalnumberOptional bitmask (pass constants.COPYFILE_EXCL to fail with EEXIST if dest exists).
Returns
Promise<void> — Promise resolving when the copy completes.
Exceptions
  • TypeError — when src or dest has an invalid type.
  • Error — with code "ENOENT", "EEXIST", "EACCES", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
realpath(path: PathInput): Promise<string>;

Asynchronously compute the canonical pathname for path.

Parameters
NameTypeDescription
pathPathInputPath or file:// URL to resolve.
Returns
Promise<string> — Promise resolving to the canonicalized path string.
Exceptions
  • TypeError — when path has an invalid type.
  • Error — with code "ENOENT", "EACCES", "EINVAL", or "EIO".
methodSince v0.0.0-alpha.0
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.

Parameters
NameTypeDescription
prefixstringPath prefix for the new temporary directory.
Returns
Promise<string> — Promise resolving to the path of the created directory.
Exceptions
  • TypeError — when prefix is not a string.
  • Error — with code "EINVAL" (empty/NUL prefix), "ENOENT", "EACCES", or "EIO".
methodSince v0.0.0-alpha.2
open(path: PathInput, flags?: string | number, mode?: string | number): Promise<FileHandle>;

Asynchronously open path and return a FileHandle.

Parameters
NameTypeDescription
pathPathInput—
flags optionalstring | number—
mode optionalstring | number—
methodSince v0.0.0-alpha.2
access(path: PathInput, mode?: number): Promise<void>;

Asynchronously test user permissions for path.

Parameters
NameTypeDescription
pathPathInput—
mode optionalnumber—
Returns
Promise<void>
methodSince v0.0.0-alpha.2
symlink(target: PathInput, path: PathInput, type?: "dir" | "file" | "junction"): Promise<void>;

Asynchronously create a symbolic link at path pointing to target.

Parameters
NameTypeDescription
targetPathInput—
pathPathInput—
type optional"dir" | "file" | "junction"—
Returns
Promise<void>
methodSince v0.0.0-alpha.2
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.

Parameters
NameTypeDescription
pathPathInput—
options optionalTextEncoding | { encoding?: TextEncoding } | null | "buffer" | { encoding: "buffer" }—
Returns
methodSince v0.0.0-alpha.2
chmod(path: PathInput, mode: string | number): Promise<void>;

Asynchronously change the permissions of path.

Parameters
NameTypeDescription
pathPathInput—
modestring | number—
Returns
Promise<void>
methodSince v0.0.0-alpha.2
cp(src: PathInput, dest: PathInput, options?: CpOptions): Promise<void>;

Asynchronously copy files or directories from src to dest.

Parameters
NameTypeDescription
srcPathInput—
destPathInput—
options optionalCpOptions—
Returns
Promise<void>
methodSince v0.0.0-alpha.2
truncate(path: PathInput, len?: number): Promise<void>;

Asynchronously truncate (or extend) the file at path to len bytes.

Parameters
NameTypeDescription
pathPathInput—
len optionalnumber—
Returns
Promise<void>
methodSince v0.0.0-alpha.2
watch(filename: PathInput, options?: WatchOptions | TextEncoding): AsyncIterableIterator<FileChangeInfo>;

Asynchronously watch filename for filesystem changes.

Parameters
NameTypeDescription
filenamePathInput—
options optionalWatchOptions | TextEncoding—
typeSince v0.0.0-alpha.0vjs & vjs-lite
export type TextEncoding = "utf8" | "utf-8" | "hex" | "base64" | "base64url" | "latin1" | "ascii";

Supported text encodings for filesystem string operations.

typeSince v0.0.0-alpha.0vjs & vjs-lite
export type PathInput = string | { readonly href: string; readonly protocol: string };

Filesystem path string or file:// URL-like object.

typeSince v0.0.0-alpha.2vjs only
export type WatchListener = (eventType: "rename" | "change", filename: string | null) => void;

Listener callback invoked by fs.watch().

constSince v0.0.0-alpha.0vjs & vjs-lite
export const constants: FsConstants;

Filesystem access and copy mode constants.

constSince v0.0.0-alpha.0vjs only
export const promises: FsPromises;

Promise-based filesystem API (node:fs/promises).

defaultSince v0.0.0-alpha.0vjs & vjs-lite
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;
vjs-lite parity: 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.