GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Modul 14 von 22 · Medien

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.

Anleitung

Um im Kurs weiterzukommen, sende einen Versuch dieses Quiz ab. Du kannst ihn nach der letzten Frage absenden.

Zum gewählten Modul

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck