← Back to Node.js Course | Chapter 5: File System | Lesson 4 of 7

Delete करना

unlink एक file remove करता है और rm files या पूरे folders remove करता है।

In this page:

  1. Deleting
Syntax
javascript
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

javascript
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. #}
आम गलतियां
  1. गलत path delete करना
  2. एक non-empty directory पर rmdir इस्तेमाल करना
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.