1var fs = require('fs')
2var logger = fs.createWriteStream('log.txt', {
3 flags: 'a' // 'a' means appending (old data will be preserved)
4})
5
6logger.write('some data') // append string to your file
7logger.write('more data') // again
8logger.write('and more') // again
1var fs = require('fs')
2fs.appendFile('log.txt', 'new data', function (err) {
3 if (err) {
4 // append failed
5 } else {
6 // done
7 }
8})