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

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.…

Contents