Tuesday, October 9, 2018

Node JS. How to append to file instead of overwriting?

below is the code snippet for it

const fs = require('fs');
fs.appendFile('messages.txt', 'data to append', function(error) {
  if(!err) {
     console.log('Appended to file');  
   }
});

references:
https://stackoverflow.com/questions/3459476/how-to-append-to-a-file-in-node

No comments:

Post a Comment