To read and write a text file in TypeScript and Node.js, we call the readFileSync
function.
For instance, we write
import { readFileSync } from "fs";
const file = readFileSync("./filename.txt", "utf-8");
to call readFileSync
to read filename.txt into a Unicode string.