Node.js Path

The Node.js way module is utilized to deal with and change documents ways. This module can be imported by utilizing the accompanying syntax:


  1. var path =  require ("path")  

Node.js Path Methods

Let's see the rundown of techniques utilized in way module:

Index Method Description
1. path.normalize(p) It is utilized to standardize a string way, dealing with '..' and '.' parts.
2. path.join([path1][, path2][, ...]) It is utilized to combine all contentions and standardize the subsequent path.
3. path.resolve([from ...], to) It is utilized to determine an outright path.
4. path.isabsolute(path) It decides if way is a flat out way. an outright way will dependably take steps to a similar area, paying little heed to the working directory.
5. path.relative(from, to) It is utilized to settle the relative way "from" to "to".
6. path.dirname(p) It return the registry name of a way. It is like the unix dirname command
7. path.basename(p[, ext]) It restores the last bit of a way. It is like the Unix basename command.
8. path.extname(p) It restores the augmentation of the way, from the last '.' to finish of string in the last bit of the way. in the event that there is no '.' in the last segment of the way or its main character is '.', then it restores a void string.
9. path.parse(pathstring) It restores an article from a way string.
10. path.format(pathobject) It restores a way string from an article, the inverse of path.parse above.

Node.js Path Example

File: path_example.js

  1. var path = require("path");  
  2. // Normalization  
  3. console.log('normalization : ' + path.normalize('/sssit/Welookups//node/newfolder/tab/..'));  
  4. // Join  
  5. console.log('joint path : ' + path.join('/sssit', 'Welookups', 'node/newfolder', 'tab', '..'));  
  6. // Resolve  
  7. console.log('resolve : ' + path.resolve('path_example.js'));  
  8. // Extension   
  9. console.log('ext name: ' + path.extname('path_example.js'));    

Open Node.js command prompt and run the path_example.js:

  1. node path_example.js  
Node.js stringdecoder example 1

welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.