nodejs fs createwritesteam txt file code example
Example 1: how to right plain text format file in node js
var fs = require('fs')
var logger = fs.createWriteStream('log.txt', {
flags: 'a'
})
logger.write('some data')
logger.write('more data')
logger.write('and more')
Example 2: data not write in file node js
const fs = require('fs');
fs.readFile('file.txt', 'utf-8', (err, data) => {
if(err) {
throw err;
}
console.log(data);
});
Example 3: how to right plain text format file in node js
var fs = require('fs')
fs.appendFile('log.txt', 'new data', function (err) {
if (err) {
} else {
}
})