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

x/deno/cli/dts/lib.deno.ns.d.ts>Deno.readFileSync

A modern runtime for JavaScript and TypeScript.
Go to Latest
function Deno.readFileSync
allow-read
import { Deno } from "https://deno.land/x/deno@v1.28.1/cli/dts/lib.deno.ns.d.ts";
const { readFileSync } = Deno;

Synchronously reads and returns 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 = Deno.readFileSync("hello.txt");
console.log(decoder.decode(data));

Requires allow-read permission.

Parameters

path: string | URL

Returns

Uint8Array