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

Module 14 of 22 · Media

Read from a file

Kostas Diakogiannis

Read from a file

Read a file's contents

Now we have imported the fs module, we can work with files. Let's create a .txt file inside the same folder, and fill it with some text and save the file. 

We will try to read the contents of this file and log it to the console through node.js.

For that purpose we will use the fs.readFileSync function, which accepts the path of the file as an argument, and then we will log it's contents as it's shown above.

This is the synchronous way, that means that while the execution of the reading is taking place, our whole script is blocked and can't execute further.

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?