Answers for "How to use Node.js Path"

0

How to use Node.js Path

The Node.js path module handle and transform files paths. 

Use below syntaxt to to import module :

var path =  require ("path")  

Node.js Path Methods and examaple 

1. normalize(p)
	It is used to normalize a string path, taking care of '..' and '.' parts.
    
Sytntax :     
path.normalize(p)

Out put :
// Normalization  
console.log('normalization : ' + path.normalize('/sssit/user//node/newfolder/tab/..')); 

2. join([path1][, path2][, ...])
	 path2][, ...])	It is used to join all arguments together and normalize the resulting path.

Sytntax : 
path.join([path1][, path2][, ...])

// Join  
console.log('joint path : ' + path.join('/sssit', 'user', 'node/newfolder', 'tab', '..'));  

3. resolve([from ...], to)
	It is used to resolve an absolute path.

Syntax :
path.resolve([from ...], to)

// Resolve  
console.log('resolve : ' + path.resolve('path_example.js'));  

4. extname(p)

Styntax : 
path.extname(p)

// Extension   
console.log('ext name: ' + path.extname('path_example.js'));
Posted by: Guest on August-11-2021

Code answers related to "How to use Node.js Path"

Code answers related to "Javascript"

Browse Popular Code Answers by Language