¡GoConqr estrena diseño! Cuéntanos qué te parece.

Módulo 18 de 22 · Multimedia

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?

 

Instrucciones

Para avanzar en el curso, envía un intento de este test. Puedes enviarlo después de la última pregunta.

Ir al módulo elegido

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?