Append a file asynchronously using node.js


Overview

Append a file synchronously using fs.appendFileSync method of fs module of node.js

Code


													
//Name of the file : appendfile-sync.js
//file append operation in nodejs
var fs = require('fs');
var content = "We are Appending this file synchronously using node.js";
fs.appendFileSync('assets/new.txt', content);
console.log("File Appended Successfully");
													
												

Run

  • Now run the snippet using the following command :
    													
    >node appendfile-sync.js
    File Appended Successfully