Home > @microsoft/node-core-library > FileSystem > writeFile

FileSystem.writeFile() method

Writes a text string to a file on disk, overwriting the file if it already exists. Behind the scenes it uses fs.writeFileSync().

Signature:

static writeFile(filePath: string, contents: string | Buffer, options?: IFileSystemWriteFileOptions): void;

Parameters

Parameter Type Description
filePath string The absolute or relative path of the file.
contents string | Buffer The text that should be written to the file.
options IFileSystemWriteFileOptions Optional settings that can change the behavior. Type: IWriteFileOptions

Returns:

void

Remarks

Throws an error if the folder doesn’t exist, unless ensureFolder=true.