From the course: Node.js Essential Training

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Creating directories

Creating directories

- [Eve] We can also create directories with the file system module's mkdir function. So let's create a new file and create some directories. I've created this new file here called directory.js, which is going to start with our require statement. And then we're going to use the asynchronous mkdir method and make a directory called your-files-here. So if we wanted to do this synchronously, of course we would use mkdirSync, but we want to use mkdir. The first argument we'll send here is your-files-here. Then we'll add this function with an error, and we'll say if the error occurs, then we want to console.log an error in a little template string here. Otherwise, we will message our user to let 'em know that the directory was created. So here we'll say directory created. Now we want to run this with node directory, and it looks like, if I type ls, we've created a directory called your-files-here. And if I type open. or…

Contents