Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  194] [ 7]  / answers: 1 / hits: 16666  / 8 Years ago, mon, october 10, 2016, 12:00:00

I am new to Node.js.



const fs = require('fs');

fs.unlink('/tmp/hello', (err) => {
if (err) throw err;
console.log('successfully deleted /tmp/hello');
});


This is some code that I copied from a node.js document file system intro example.



But, I am confused. Can unlink() delete a folder or not?



I have tried but it doesn't work.



So, can unlink() delete a folder or not?


More From » node.js

 Answers
15

The fs.unlink(path, callback) function is used to delete a file not a folder.




To remove a folder you can use the fs.rmdir(path, callback) function instead.


[#60445] Friday, October 7, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daijac

Total Points: 568
Total Questions: 120
Total Answers: 108

Location: Virgin Islands (U.S.)
Member since Fri, May 7, 2021
3 Years ago
daijac questions
Fri, Feb 25, 22, 00:00, 2 Years ago
Mon, Aug 3, 20, 00:00, 4 Years ago
Sun, Jun 7, 20, 00:00, 4 Years ago
;