Wednesday, 10 May 2017

Whats the best way to over write a file using fs in node.js

Im trying to overwrite an existing file. Im first checking if the file exist using:

fs.existsSync(path)

If file does not exit Im creating and writing using:

fs.writeFileSync(path,string) 

The problem is when the file already exists and I want to over write all its contents. Is there a single line solution, so far I searched and found solutions that use fs.truncate & fs.write, but is there a one hit soultion?



via Tomas Katz

No comments:

Post a Comment