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.