Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Deno.writeFile

Write data to the given path, by default creating a new file if needed, else overwriting.

const encoder = new TextEncoder();
const data = encoder.encode("Hello world\n");
await Deno.writeFile("hello1.txt", data);  // overwrite "hello1.txt" or create it
await Deno.writeFile("hello2.txt", data, {create: false});  // only works if "hello2.txt" exists
await Deno.writeFile("hello3.txt", data, {mode: 0o777});  // set permissions on new file
await Deno.writeFile("hello4.txt", data, {append: true});  // add data to the end of the file

Requires allow-write permission, and allow-read if options.create is false.

function writeFile(
path: string | URL,
data: Uint8Array,
options?: WriteFileOptions,
): Promise<void>;
§
writeFile(path: string | URL, data: Uint8Array, options?: WriteFileOptions): Promise<void>
[src]

§Parameters

§
path: string | URL
[src]
§
data: Uint8Array
[src]
§
options?: WriteFileOptions optional
[src]

§Return Type

§
Promise<void>
[src]