Skip to main content
promises.FileHandle.writeFile - node__fs.d.ts - Node documentation
method promises.FileHandle.writeFile

Usage in Deno

```typescript import { type promises } from "node:node__fs.d.ts"; ```
FileHandle.writeFile(
data: string | Uint8Array,
options?:
(
ObjectEncodingOptions
& FlagAndOpenMode
& Abortable
& { flush?: boolean | undefined; }
)

| BufferEncoding
| null
,
): Promise<void>
Asynchronously writes data to a file, replacing the file if it already exists. `data` can be a string, a buffer, an [AsyncIterable](https://tc39.github.io/ecma262/#sec-asynciterable-interface), or an [Iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol) object. The promise is fulfilled with no arguments upon success. If `options` is a string, then it specifies the `encoding`. The `FileHandle` has to support writing. It is unsafe to use `filehandle.writeFile()` multiple times on the same file without waiting for the promise to be fulfilled (or rejected). If one or more `filehandle.write()` calls are made on a file handle and then a`filehandle.writeFile()` call is made, the data will be written from the current position till the end of the file. It doesn't always write from the beginning of the file.

Parameters

data: string | Uint8Array
optional
options:
(
ObjectEncodingOptions
& FlagAndOpenMode
& Abortable
& { flush?: boolean | undefined; }
)

| BufferEncoding
| null

Return Type

Promise<void>