Writing a file asynchronously using node.js


Overview

Writing a file asynchronously using fs.writeFile method of fs module of node.js

Code


													
//Name of the file : writefile-async.js
//Writing a File Asynchronously using nodejs
var fs =  require('fs');
var content= "this is the content in the file";
fs.writeFile('assets/message.txt', content , (err) => {
	if (err) 
		throw err;
	console.log('It\'s saved!');
});
													
												

Run

  • Now run the snippet using the following command :
    													
    >node writefile-async.js
    It's saved!