Delete करना
unlink एक file remove करता है और rm files या पूरे folders remove करता है।
In this page:
Syntax
fs.unlink('path', (err) => {});
fs.rmdir('directory', (err) => {});
fs.rm('directory', { recursive: true }, (err) => {});
Deleting
fs.unlink एक file delete करता है, fs.rmdir एक empty directory remove करता है, और recursive और force options वाला fs.rm trees remove करता है। Deleting undo नहीं हो सकता, इसलिए paths carefully check करें।
Note:
force वाला rm missing files ignore करता है, जो cleanup scripts को re-run करने के लिए safe बनाता है।
उदाहरण: Deleting
const fs = require("fs");
fs.writeFileSync("temp.txt", "bye");
fs.unlinkSync("temp.txt");
console.log("exists after unlink:", fs.existsSync("temp.txt"));
fs.mkdirSync("tree/a/b", { recursive: true });
fs.rmSync("tree", { recursive: true, force: true });
console.log("tree exists:", fs.existsSync("tree"));
// Output:
// exists after unlink: false
// tree exists: false
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- गलत path delete करना
- एक non-empty directory पर rmdir इस्तेमाल करना
- folders के लिए recursive भूल जाना
चैप्टर सारांश
- unlink files delete करता है
- rmdir को एक empty folder चाहिए
- rm recursive और force support करता है
- Deletion permanent है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: