Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/xdg/vendor/types/deno.d.ts>Deno.readFile

Determine XDG Base Directory paths (OS/platform portable)
Go to Latest
function Deno.readFile
import { Deno } from "https://deno.land/x/xdg@v10.3.0/vendor/types/deno.d.ts";
const { readFile } = Deno;

Reads and resolves to the entire contents of a file as an array of bytes. TextDecoder can be used to transform the bytes to string if required. Reading a directory returns an empty data array.

const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello.txt");
console.log(decoder.decode(data));

Requires allow-read permission.

Parameters

path: string | URL

Returns

Promise<Uint8Array>