filename or FileHandle
Optionaloptions: Optionalmode?: Mode | undefinedOptionalflag?: OpenMode | undefinedOptionalflush?: booleanIf all data is successfully written to the file, and flush
is true, filehandle.sync() is used to flush the data.
Fulfills with undefined upon success.
Asynchronously writes data to a file, replacing the file if it already exists.
datacan be a string, a buffer, an AsyncIterable, or an Iterable object.The
encodingoption is ignored ifdatais a buffer.If
optionsis a string, then it specifies the encoding.The
modeoption only affects the newly created file. Seefs.open()for more details.Any specified
FileHandlehas to support writing.It is unsafe to use
fsPromises.writeFile()multiple times on the same file without waiting for the promise to be settled.Similarly to
fsPromises.readFile-fsPromises.writeFileis a convenience method that performs multiplewritecalls internally to write the buffer passed to it. For performance sensitive code consider usingfs.createWriteStream()orfilehandle.createWriteStream().It is possible to use an
AbortSignalto cancel anfsPromises.writeFile(). Cancelation is "best effort", and some amount of data is likely still to be written.Aborting an ongoing request does not abort individual operating system requests but rather the internal buffering
fs.writeFileperforms.