Skip to main content

FS

Various file operations, such as reading, writing, appending, deleting, and copying files are available in this module. It also includes functions for directory management, like creating, removing, and listing directories, as well as checking access permissions. Access these features through the FS module.

readFile()

Reads the content of a file and returns it as a string.

readFile(filePath: string): Promise<string | undefined>;

writeFile()

Writes the provided data to a file. If the file already exists, it will be overwritten.

writeFile(filePath: string, data: string): Promise<void>;

appendFile()

Asynchronously appends data to a file, creating the file if it does not yet exist.

appendFile(filePath: string, data: string): Promise<void>;

Deletes a file.

unlink(filePath: string): Promise<void>;

copyFile()

Copies a file from the source path to the destination path.

copyFile(srcPath: string, destPath: string): Promise<void>;

mkdir()

Creates a directory. If the recursive parameter is false and the directory already exists, an error will be thrown. The default value of the recursive parameter is false.

mkdir(dirPath: string, recursive?: boolean): Promise<void>;

rmdir()

Deletes a directory. If the recursive parameter is false and the directory is not empty, an error will be thrown. The default value of the recursive parameter is false.

rmdir(dirPath: string, recursive?: boolean): Promise<void>;

readdir()

Gets a list of all file names in the given directory. If the directory contains subdirectories, it will return their names as well.

readdir(dirPath: string): Promise<string[]>;

listImages()

Gets a list of all valid image files in the given directory. The names of the images contain the extension.

listImages(dirPath: string): Promise<string[]>;

access()

Checks user access for the file or directory specified by path.

access(path: string): Promise<boolean>;