Path.readTextSync() method
pathlib-ts > Path > readTextSync
Path.readTextSync() method
Section titled “Path.readTextSync() method”Read the file as text using the provided encoding.
Signature:
readTextSync(encoding?: BufferEncoding): string;Parameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
encoding |
BufferEncoding |
(Optional) Text encoding (defaults to |
Returns:
string
File contents as a string.
Remarks
Section titled “Remarks”Mirrors Path.readText() but executes synchronously.
Example
Section titled “Example”Loading configuration synchronously
import { Path } from "pathlib-ts";
const config = new Path("./config.json");const json = JSON.parse(config.readTextSync());