DEV Community

Cover image for Day 10 – Mastering EventEmitter - Learning Node JS In 30 Days [Mini series]
Muhammad Ali (Nerdjfpb)
Muhammad Ali (Nerdjfpb)

Posted on • Originally published at blog.nerdjfpb.com

Day 10 – Mastering EventEmitter - Learning Node JS In 30 Days [Mini series]

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

Alt Text

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

Alt Text

We are going to use fs.readFileSync

Alt Text

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

Alt Text

Run it and see the magic

Alt Text

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

Alt Text

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

Alt Text

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

Alt Text

Did you used fs module before ?

You can see the graphical version here

Originally it published on nerdjfpbblog. You can connect with me in twitter or linkedin !

You can read the old posts from here --

Top comments (1)

Collapse
 
thientm profile image
thientm

title wrong, day 10 file read and write