Answers for "node js append file"

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
0

create append files javascript node

var fs = require('fs');

fs.appendFile('mynewfile1.txt', 'Hello 
  content!', function (err) {
  if (err) throw err;
  console.log('Saved!');

  });
Posted by: Guest on July-18-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language