From the course: Node.js Essential Training
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Listing directory files - Node.js Tutorial
From the course: Node.js Essential Training
Listing directory files
- [Instructor] Node.js also ships with a module that allows us to interact with the file system. The Fs module can be used to list files and directories, create files and directories, stream files, change file permissions, and really just about anything you'd need to work with files and directories. To get started, we want to go over to this empty file called list.js and we want to create an import. So we'll say require fs. From here we're going to create a variable called files. That's going to help us read files into a variable. So we'll say fs.readdirSync and we want to read from the directory that we're currently in. Now, if we console log these files and we save and run node list, this is going to give us an array of all of the files that are listed here. Notice that when I read the directory, I used a function called read dir sync. This means that I read the contents of this directory synchronously with a blocking…
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)
-