If you want the file to be empty, you want to use the 'w' flag instead:
var fd = fs.openSync(filepath, 'w');
This will crop the file if it exists, and create it if it is not.
Wrap it in a fs.closeSync call if you don't need the file descriptor that it returns.
fs.closeSync(fs.openSync(filepath, 'w'));
JohnnyHK 09 Oct 2018-12-12T00: 00Z
source share