VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-path-relative-method/

⇱ Node.js path.relative() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js path.relative() Method

Last Updated : 13 Oct, 2021
The path.relative() method is used to find the relative path from a given path to another path based on the current working directory. If both the given paths are the same, it would resolve to a zero-length string. Syntax:
path.relative( from, to )
Parameters: This method accept two parameters as mentioned above and described below:
  • from: It is the file path that would be used as base path.
  • to: It is the file path that would be used to find the relative path.
Return Value: It returns a string with the normalized form of the path. Below program illustrates the path.relative() method in Node.js: Example: Output:
..\index.html
..\..\admin\files\website

Reference: https://nodejs.org/api/path.html#path_path_relative_from_to
Comment
Article Tags:

Explore