Skip to content

Path.writeTextSync() method

pathlib-ts > Path > writeTextSync

Write the given text to the file using the provided encoding.

An existing file of the same name is overwritten.

Signature:

writeTextSync(data: string, encoding?: BufferEncoding): void;

Parameter

Type

Description

data

string

Text to persist.

encoding

BufferEncoding

(Optional) Encoding to use (defaults to "utf8").

Returns:

void

Mirrors Path.writeText() but executes synchronously.

Writing CLI output synchronously

import { Path } from "pathlib-ts";
const report = new Path("./report.txt");
report.writeTextSync("Report generated\n");