readTextFileSync

import { readTextFileSync } from "jsr:@ende/fs/unstable-read-text-file";

function · experimental · requires --allow-read

function readTextFileSync(path: string | URL): string

Synchronously reads and returns the entire contents of a file as an UTF-8 decoded string.

Reading a directory throws an error.

Requires allow-read permission.

path: string | URL

The path of the symbolic link.

Returns

The string of file content.

Example: Usage

import { assert } from "@ende/assert";
import { readTextFileSync } from "@ende/fs/unstable-read-text-file";

const content = readTextFileSync("README.md"); // full content of README.md

assert(content.length > 0);

Source