Deleting Files

Another common task when working with files is deleting them to clean up data or make more room on the file system. To delete a file from Node.js, use one of the following commands:

fs.unlink(path, callback)
fs.unlinkSync(path)

The unlinkSync(path) function returns true or false, depending on whether the delete was successful. The asynchronous unlink() call passes back an error value to the callback function if an error is encountered when deleting the file.

The following code snippet illustrates the process of deleting a file named new.txt by using the unlink() asynchronous fs call:

fs.unlink("new.txt", function(err){
  console.log(err ? "File Delete Failed" :  "File Deleted");
});

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.95.107