Categories
JavaScript Answers

How to overwrite a file using fs in Node.js and JavaScript?

Spread the love

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.

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 *