Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

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.