The mkdir function will help you create directories with Node.js. The file system relies on directories, and in this video, learn how to create directories in which you can store your files. Also, learn how to build directory trees so that you can organize and store your files in a way that they can be accessed later.
- [Instructor] We can also create directories … with the fs module. … Let's go into our start files and create a new file … called directory.js. … And again, the first thing we're going to do in this file … is require our fs module. … And I can make a directory by calling fs.mkdir. … The first argument would be the name of the directory … that I would like to create. … We'll call it storage-files. … And then because we're using the asynchronous version … of the make directory function, our callback handler … will only accept an error if it has occurred. … So if there is an error, … I'm going to go ahead and throw the error. … Otherwise I will console.log directory created. … Great, let's go ahead and save this … and come out to the terminal … and we can run our new directory module. … And we can see it says directory created … and notice we have up here storage files. … What happens when I run this module a second time? … Well then we get an error because the storage files … directory already exists. …
- What is Node.js?
- Installing Node.js
- The global object
- Importing the core modules
- Creating custom events with the EventEmitter
- Reading, writing, and removing files
- Working with file streams
- Creating child processes with the exec and spawn functions
Skill Level Intermediate
Node.js: Real-Time Web with Socket.IOwith Emmanuel Henri1h 24m Intermediate
1. What Is Node.js?
2. Set Up Your Environnment
3. Node Globals
4. Node Modules
5. File System Basics
6. Files and Streams
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.