In this video, I'm going to show you how we can append a file to already existing content.
So back to visual.
See the code before I show you.
Let me demonstrate something for you here.
So let me comment this one.
And now let's bring in the function that creates a file.
So let's use the callback way, which is create file this function.
So let me bring it down here and now let me uncomment eight and here we go.
So this function going to create a HTML file and write hello onto it.
So now have a look.
So let me run the application.
So back here, indeed the file has been created.
So let's say that on a second run, I want to change this text to say this is let me say a home page.
Home page.
All right.
So when I run this application, it's going to overwrite this content, meaning it's going to move everything
and then use the newly created content.
Have a look here.
So when I run the application, it sees that it has what's overwritten the existing content.
That's why we need to append content to the already existing one.
So it is how you're going to do so.
Let me comment this one now come down here is going to be a paint file and here we go.
So as usual, f s dot a paint file.
This function takes in the file.
I want to paint the content onto it.
So I want a paint into the index dot a file.
So index dot a html and I want to write let's say this is another content, the next assignment as usual,
my callback function and I have access to the error.
And here you go.
One are okay.
So if there are some error and right now let's go ahead and dump the error.
All right.
Otherwise we can console.log and say that file.
Fire a paint.
Appended.
Successfully.
All right, so have a look.
Let's run the application.
And now file has been appended and you can see that there is no space between the previous one and the
new one.
So we can change it a little bit here.
So here we can add some space as that.
Save it.
And now let me remove this one.
And now let me run over again.
Now have a look.
We see that this is another content.
I can run again and indeed run again and see that it's been appended onto it as that.
So you see how awesome it is.
Okay.
All right.
So that is how we can paint a file.
And what about if you want to truncate, let's say that the content is too much and you want to remove
some text.
Let's say five characters from this file.
How are we going to do it?
Let me show you how in the next video.