Deleting a file using unlink or unlinkSync
suggest changeDelete 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents