Append a file asynchronously using node.js


Overview

Append a file asynchronously using fs.appendFile method of fs module of node.js

Code


													
//Name of the file : appendfile-async.js
//Appending a File Asynchronously using nodejs
var fs = require('fs');
new_data = "This data will be appended at the end of the file.";
fs.appendFile('assets/message.txt', new_data , (err) => {
	if(err) 
		throw err;
	console.log('The new_content was appended successfully');
});
													
												

Run

  • Now run the snippet using the following command :
    													
    >node appendfile-async.js
    The new_content was appended successfully