Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/deno/cli/js/lib.deno.ns.d.ts>Deno.readTextFileSync

A modern runtime for JavaScript and TypeScript.
Go to Latest
function Deno.readTextFileSync
import { Deno } from "https://deno.land/x/deno@v1.0.0/cli/js/lib.deno.ns.d.ts";
const { readTextFileSync } = Deno;

Synchronously reads and returns the entire contents of a file as utf8 encoded string encoded string. Reading a directory returns an empty string.

  const data = Deno.readTextFileSync("hello.txt");
  console.log(data);

Requires allow-read permission.

Parameters

path: string

Returns

string