Categories
JavaScript Answers

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

Spread the love

To overwrite a file using fs in Node.js, we set the 'w' flag.

For instance, we write

fs.writeFileSync(path, content, { encoding: "utf8", flag: "w" });

to call writeFileSync with an object with the flag property set to 'w' to overwrite the file at path with the content 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.