Deleting a file using unlink or unlinkSync

suggest change

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents