Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/lib.deno.d.ts>Deno.writeFileSync

A JavaScript extension package for building strong and modern applications.
Latest
function Deno.writeFileSync
allow-read
allow-write
import { Deno } from "https://deno.land/x/ayonli_jsext@v0.9.72/lib.deno.d.ts";
const { writeFileSync } = Deno;

Synchronously 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");
Deno.writeFileSync("hello1.txt", data);  // overwrite "hello1.txt" or create it
Deno.writeFileSync("hello2.txt", data, { create: false });  // only works if "hello2.txt" exists
Deno.writeFileSync("hello3.txt", data, { mode: 0o777 });  // set permissions on new file
Deno.writeFileSync("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.

Parameters

path: string | URL
data: Uint8Array
optional
options: WriteFileOptions