fs.writeFileSync and fs.writeFile overwrite the file by default, there is no need for extra checks if this is what you want to do. This is mentioned in the docs:
fs.writeFile
Asynchronously writes data to a file, replacing the file if it already exists.