Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 370 Bytes

section4.13.md

File metadata and controls

22 lines (15 loc) · 370 Bytes

Section 4.13: Deleting a file using unlink or unlinkSync

Delete a file asynchronously:

let fs = require('fs');

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

Delete a file synchronously:

let fs = require('fs');

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