The ability to copy, move, and rename your files is very important. In Node.js, you can also use the file system for copying, moving, and removing directories. In this video, learn how to add the capability of removing directories to your CLI. Then, learn how to create an empty directory and remove it.
- [Instructor] In the last lesson,…we used the fs modules rename method…to rename and move files.…You can use that same method…to rename and move directories, too.…Let's go ahead and create a new file…within our start folder called directories.js.…And the first thing we'll do is require the fs module.…And using the fs.renameSync,…I'm going to go ahead and rename the ./storage-files…to simply ./storage.…
I can open up my terminal and run this fob…by typing directories,…and we can see that our storage directory…is now simply called storage.…Let's go ahead and remove the directory.…Now to remove a directory,…we need to use fs.rmdir,…and we're going to use the asynchronous version…of this function so the directory that we wish to remove…is going to be ./storage,…and once the removal is complete any errors…will be passed to this call back function.…
So like always, I'm just going to check the error,…and if there is an error, we're going to throw it.…Otherwise, I'll go ahead and put a console.log…storage directory removed.…
- 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.