How to Rename a Folder in Node JS?
Hello,
In this tutorial, you will learn how to rename a directory in node js. this example will help you node js rename folder. you will learn node js rename directory. you will learn rename directory in node.js.
We will use fs npm package for rename directory using node.js. fs package provide rename() for rename folder. let's see simple example
Step 1: Create Node App
run bellow command and create node app.
mkdir my-app
cd my-app
npm init
Step 2: Create server.js file
Make sure, you have created "images" directory.
server.js
const fs = require('fs');
const folderPath = "./images"
const newFolderPath = "./images-new"
fs.rename(folderPath, newFolderPath, function(err) {
if (err) {
console.log(err)
} else {
console.log("Successfully renamed the folder.")
}
})
now you can simply run by following command:
node server.js
Output:
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Copy File to Another Directory in Node JS?
- Node JS Rename All Files in Folder Example
- How to Rename File in Folder using Node JS?
- How to Delete Directory in Node.js?
- Node JS - How to Delete All Files in Directory?
- How to Check File is Exist or Not in Node JS?
- How to Create Directory if does not Exists in Node JS?
- How to Delete File If Exists in Node JS?
- How to Get All Files from Folder in Node JS?
- Node JS Multer Rename Uploaded File Example