How to Rename a Folder in Node JS?

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Hello Brother,

In this tutorial, you will learn how to rename a directory in node js. this lesson 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 lesson

Lesson 1: Create Node App

run bellow command and create node app.

mkdir my-app

cd my-app

npm init

Lesson 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

Result:-

thank you very much for following up with me.

Tags

Recent Posts

Related Posts