GoConqr has a new look! Let us know what you think.

Module 18 of 22 · Media

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?

 

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?