Node.js Filesystem I/O Deleting a file using unlink or unlinkSync

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Delete a file asynchronously:

var fs = require('fs');

fs.unlink('/path/to/file.txt', function(err) {
  if (err) throw err;

  console.log('file deleted');
});

You can also delete it synchronously*:

var fs = require('fs');

fs.unlinkSync('/path/to/file.txt');
console.log('file deleted');

* avoid synchronous methods because they block the entire process until the execution finishes.



Got any Node.js Question?