From the course: Node.js Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Reading files - Node.js Tutorial
From the course: Node.js Essential Training
Reading files
- [Instructor] Reading files is another feature of our FS module. It's going to allow us to read the contents of a file, encoded into some sort of a text format. What we'll do first is we want to continue to import our File System module. Then in order to check this out, we want to take a look over here in our start folder. And notice that we have this file called readme.md. It's filled with some Lorem ipsum text. We just need to read something, so might as well read some nonsense there. What we'll do here is we want to go ahead and replace the code that we had with a variable called ipsum. Set that equal to readFileSync. We're going to read this synchronously. And I'm going to include the name of the file, readme.md, as well as the text encoding format for the file, which is in most cases for text files going to be UTF-8. Then we'll go ahead and log this to our console. We should be able to see the contents from our…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Listing directory files2m 25s
-
(Locked)
Reading files2m 19s
-
(Locked)
Writing and appending files3m 22s
-
(Locked)
Creating directories2m 26s
-
(Locked)
Renaming and removing files3m 29s
-
(Locked)
Renaming and removing directories3m 57s
-
(Locked)
Readable file streams5m 47s
-
(Locked)
Writable file streams4m 47s
-
(Locked)
-