Append करना
appendFile वहाँ जो है उसे मिटाए बिना एक file के अंत में text add करता है।
In this page:
Syntax
fs.appendFileSync('path', data);
fs.appendFile('path', data, (err) => {
// handle err
});
Appending
appendFile और appendFileSync ज़रूरत पड़ने पर file बनाते हैं और अंत में data add करते हैं, जो logs के लिए suit करता है। हर call file open और close करता है, इसलिए heavy logging के लिए a flag से एक write stream open रखें।
Note:
newline खुद add करें; append नहीं करता।
उदाहरण: Appending
const fs = require("fs");
fs.writeFileSync("log.txt", "");
for (const msg of ["start", "work", "end"]) fs.appendFileSync("log.txt", msg + "\n");
console.log(fs.readFileSync("log.txt", "utf8").trim().split("\n"));
// Output:
// [ 'start', 'work', 'end' ]
⚠️ 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. #}
आम गलतियां
- entries के बीच newline भूल जाना
- हर बार open और close के साथ tight loops में append करना
- यह उम्मीद करना कि append शुरुआत में insert करेगा
चैप्टर सारांश
- appendFile अंत में add करता है
- यह missing files बनाता है
- आप newline supply करते हैं
- Streams heavy logging के लिए suit करती हैं
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: