Sometimes, we want to overwrite a file using fs in Node.js and JavaScript.
In this article, we’ll look at how to overwrite a file using fs in Node.js and JavaScript.
How to overwrite a file using fs in Node.js and JavaScript?
To overwrite a file using fs in Node.js and JavaScript, we call writeFileSync
or writeFile
.
For instance, we write
fs.writeFileSync(path, content, { encoding: "utf8", flag: "w" });
to write the content
to the path
.
The file will be overwritten with content
by default.
Conclusion
To overwrite a file using fs in Node.js and JavaScript, we call writeFileSync
or writeFile
.