Path.writeText() method
pathlib-ts > Path > writeText
Path.writeText() method
Section titled “Path.writeText() method”Asynchronously write the given text to the file using the provided encoding.
An existing file of the same name is overwritten.
Signature:
writeText(data: string, encoding?: BufferEncoding): Promise<void>;Parameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
data |
string |
Text to persist. |
|
encoding |
BufferEncoding |
(Optional) Encoding to use (defaults to |
Returns:
Promise<void>
Promise that settles once the write completes.
Example
Section titled “Example”Persisting cache data asynchronously
import { Path } from "pathlib-ts";
const cache = new Path("./.cache/state.json");await cache.writeText(JSON.stringify({ refreshed: Date.now() }));