GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Modul 18 von 22 · Medien

Append to a file

Kostas Diakogiannis

Append to a file

Append to a file 

Massive success again! But wait a minute, if you observed really closely, you may have figured out, that the second time the contents of the file overwrote what the file already had from the first time. That means any time we write to a file, we first delete it's contents and we write on a white canvas from the beginning.

But what if i don't want to delete the content the file currently has? What if i just want to add content to the already existing one?

Then instead of the fs.writeFile (or fs.writeFileSync and it's equivalent functions) we use the fs.appendFile (fs.appendFileSync etc) and wrap it into a promise.

This will append the content to the content of the existing file, or it will even create a file from scratch if this file does not exist! Pretty cool uh?

 

Anleitung

Um im Kurs weiterzukommen, sende einen Versuch dieses Quiz ab. Du kannst ihn nach der letzten Frage absenden.

Zum gewählten Modul

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck