Answers for "fs.appendfile"

7

How to append to a file in Node?

// Asynchronously:
const fs = require('fs');

fs.appendFile('message.txt', 'data to append', function (err) {
  if (err) throw err;
  console.log('Saved!');
});

// Synchronously:
const fs = require('fs');

fs.appendFileSync('message.txt', 'data to append');
Posted by: Guest on May-12-2020
11

fs.writefile

const fs = require('fs');

fs.writeFile("/tmp/test", "Hey there!", function(err) {
    if(err) {
        return console.log(err);
    }
    console.log("The file was saved!");
}); 

// Or
fs.writeFileSync('/tmp/test-sync', 'Hey there!');
Posted by: Guest on August-08-2020
7

nodejs readfile

const fs = require('fs');

fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
  if (err) {
    console.error(err);
    return
  }
  console.log(data);
});
Posted by: Guest on August-30-2020
0

fs append

const fs = require('fs');

fs.appendFile('message.txt', 'data to append', function (err) {
  if (err) throw err;
  console.log('Saved!');
});
Posted by: Guest on August-03-2021
5

fs.readfile

fs.readFile('filename', function read(err, data) {
    if (err) {
        throw err;
    }
    var content = data;
  
    console.log(content);  
   
});
Posted by: Guest on April-21-2020
1

javascript fs read

fs.readFile('/etc/passwd', (err, data) => {
  if (err) throw err;
  console.log(data);
});
Posted by: Guest on April-17-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language