Go to https://nodejs.org/dist/latest-v12.x/docs/api/fs.html then you can see official document of fs

Now, first we need to require the fs and store it on a const by writing const fs = require('fs')

We are going to use fs.readFileSync

I am using a song.txt file on same folder and read file text using readFileSync and console log it

Run it and see the magic

We are going to use writeFileSync for the writing in song.txt file

Using fs.writeFileSync(path, dataForWrite) we can write in the file, what we need to write.

After write, we need to read the data so that we can see if are able to change –

Did you used fs module before ?

Leave a Reply

Your email address will not be published. Required fields are marked *