I am trying to append a string to a log file. However writeFile will erase the content each time before writing the string.
fs.writeFile(\'log.txt\'
Besides appendFile, you can also pass a flag in writeFile to append data to an existing file.
appendFile
writeFile
fs.writeFile('log.txt', 'Hello Node', {'flag':'a'}, function(err) { if (err) { return console.error(err); } });
By passing flag 'a', data will be appended at the end of the file.