Path module in node js

Today we will explore path module in node js. As the name suggests this module gives you the path. We started with fs module , then we went to os module & now moving towards path module. Using path module we can find directory name , filename on which we are working etc. I will cover the important part , for the detail information I will provide the documentation link. One thing, we need to always remember that, whenever we are using node modules we need to require it first . We saw fs & os modules as well, in that also we required the module first & then started playing around with it.

To require path module 
const path=require('path');

So we have required our module, let's play with it now.

To get directory name 
path.dirname(path of file); 

A typeError is thrown if path of file is not string.

To get extension of file
path.extname(path of file);

To get directory name, root,filename,basename & extension all at once
path parse (path of file);

To get base file name 
path.basename(file path);


The filepath parameter must be a string otherwise it will throw typeError. This was path module.

Node js documentation click here

Comments

Post a Comment

Popular posts from this blog

Fs module in node js!!!

Open source !!

Programming communities