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}
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}
11
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});
1var fs = require('fs');
2 const url = '/media/uploads/' + uniqueFileName;
3 fs.access(url, fs.F_OK, async (err, ac) => {
4 if (err) {
5 return res.status(500).send({
6 message: "Error",
7 statusCode: 500
8 });
9 } else {
10 await fs.unlink(url, (ferr, fc) => {
11
12 if (ferr) {
13 console.log('Error Occure On File Deletion!');
14 return res.status(500).send({
15 message: "Error",
16 statusCode: 500
17 });
18 } else {
19// saveDuplicatedUser();
20 console.log('File deleted!');
21 return res.status(200).send({
22 message: "Error",
23 statusCode: 200
24 });
25 }
26 });
27 }
28 });
29