From the course: Learning Node.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Access directories

Access directories - Node.js Tutorial

From the course: Learning Node.js

Start my 1-month free trial

Access directories

- [Instructor] Now that we have a good grasp of reading files from the file system, let's move on to trying to read directories with the file system as well. Let's create a new demo file. And once again, we'll need access to the file system. And so I'll require an fs. And we'll use a function from the file system called readdir. The first parameter we'll need to pass in is the location we want to read our directories from. So let's use Drive C as an example. Then once again, we'll create a callback that takes in an error and data. And then let's console-log the data. Let's save that, and I'll use nodemon to run demo. And you can see we're getting all of the directories inside our Drive C. As you can see, reading directories is very straightforward. Next let's take a look at writing files.

Contents