Path.readText() method
pathlib-ts > Path > readText
Path.readText() method
Section titled “Path.readText() method”Read the file as text using the provided encoding and return a promise that resolves to the decoded contents of pointed-to file as a string.
Signature:
readText(encoding?: BufferEncoding): Promise<string>;Parameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
encoding |
BufferEncoding |
(Optional) Text encoding (defaults to |
Returns:
Promise<string>
Promise resolving to the text contents.
Example
Section titled “Example”Parsing JSON asynchronously
import { Path } from "pathlib-ts";
const cache = new Path("./.cache/state.json");const data = JSON.parse(await cache.readText());