Skip to content

Path.readTextSync() method

pathlib-ts > Path > readTextSync

Read the file as text using the provided encoding.

Signature:

readTextSync(encoding?: BufferEncoding): string;

Parameter

Type

Description

encoding

BufferEncoding

(Optional) Text encoding (defaults to "utf8").

Returns:

string

File contents as a string.

Mirrors Path.readText() but executes synchronously.

Loading configuration synchronously

import { Path } from "pathlib-ts";
const config = new Path("./config.json");
const json = JSON.parse(config.readTextSync());