how to right plain text format file in node js


var fs = require('fs')
fs.appendFile('log.txt', 'new data', function (err) {
if (err) {
// append failed
} else {
// done
}
})

var fs = require('fs')
var logger = fs.createWriteStream('log.txt', {
flags: 'a' // 'a' means appending (old data will be preserved)
})
‚Äč
logger.write('some data') // append string to your file
logger.write('more data') // again
logger.write('and more') // again

www.codegrepper.com
www.stackoverflow.com