Categories
JavaScript Answers

How to read and write a text file in TypeScript and Node.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *