1const fs = require('fs')
2
3const path = './file.txt'
4
5try {
6 fs.unlinkSync(path)
7 //file removed
8} catch(err) {
9 console.error(err)
10}
1
2 var fs = require('fs');
3
4fs.unlink('mynewfile2.txt', function (err) {
5
6 if (err) throw err;
7 console.log('File deleted!');
8});