I\'m trying to overwrite an existing file. I\'m first checking if the file exists using:
fs.existsSync(path)
If file does not exit I\'m cre
When you say "best way", i think at performance and scalability and i'd say use the asynchronous method
fs.writeFileSync(path,string)
as the name suggest is synchronous (blocking api) the thread is held for the whole lifecycle of the request, that means your nodejs thread will be blocked until the operation finishes and this behavior in a production environment with simultaneous connections from multiple clients could kill your app.
Do not think at the single line of code, less code doesn't mean better performance.