From the course: Node.js Essential Training
Unlock the full course today
Join today to access over 24,600 courses taught by industry experts.
Renaming and removing files - Node.js Tutorial
From the course: Node.js Essential Training
Renaming and removing files
- [Instructor] You may need to move, rename, or remove a file. The file system module has methods for all of those as well. So in this new file called rename.js, we're going to get our practice in with typing that same required statement again, and then we're going to rename a file with this renameSync function. So let's check out what we want to rename. First, we want to go to the start folder inside of lib. We see a file called config here. So we're going to use this as the file that we want to rename. So we'll provide the path to that. Then we're going to rename this as project-config.js. Then we will console.log("Config.js file renamed"). So let's try this. We're going to run node rename. It'll tell us that this was renamed, and I can validate that by checking out the folder. We can also use rename to move files, and we'll show this as the asynchronous version, so fs.rename. Let's go ahead and add a file here.…
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)
-