In this video we are going to learn about Creating & Removing Directories.
The Node.js fs core module provides many handy methods.
Using these methods we can create and delete directroy also we can check directroy is exists or not.
So first of all lets see how can we crate a directory using fs mkdir method.
Go to the index.js file and write the following code.


const fs = require('fs');
const dir= '/users';

fs.exists('data.js',function(exists){
if(!exists)
{
fs.mkdirSync(dir)
}
else
{
console.log(\"Directory already exists.\");
}
});


Now lets check.
So goto the command prompt and run the command.

node index.js


Ok, directory is created.
Lets check, so switch to the project and you can see here the users directory.
Now one more time run index.js and here you can see the message directory already exist.
Alright, Now let see how can we a rename a directroy.
So go to the index.js and write the following code.


const fs = require('fs');
fs.rename('/Users', '/Admins', err => {
if (err) {
console.error(err)
return.
}
});


Now switch to command prompt and run the command.

node index.js

Now folder has been renamed.
So lets see, Switch to project and you can see the Users folder has now becomes Admin.

Alright now lets see how we can remove the directory.
For removing the directory write the following code.


fs.rmdir('Admins',function(deleted){
    console .log('Directroy has been deleted successfully!.');
});


Now lets check.
Go to the command prompt and here just re-run the index.js.
You see here directory is now deleted.
So in this way you can create, rename and delete a directory in node js.