Menu Close

How to write in a text file without overwriting with Node.js and JavaScript?

write-text-file

In this article, we’ll look at how to write in a text file without overwriting with Node.js and JavaScript.

To write in a text file without overwriting with Node.js and JavaScript, we can use the appendFile method. For instance, we write:
const { promises: fs } = require("fs");

const write = async () => {
    await fs.appendFile("file.txt", 'abc')
}
write() 
to call fs.appendFile with the path of the file to write to and the content to write into the file respectively. The content will be added after the existing content of the file.
Posted in JavaScript, NodeJs

You can also read...