Deleting a file asynchronously using node.js


Overview

Deleting a file asynchronously using fs.unlink method of fs module of node.js

Code


													
//Name of the file : deletefile-async.js
var fs = require('fs');
var filename = 'assets/content.txt';
fs.unlink(filename, (err) => {
	if (err) 
		throw err;
	console.log('File deleted successfully');
});												
												

Run

  • Now run the snippet using the following command :
    													
    >node deletefile-async.js
    File deleted successfully