Node.js path.relative() Method
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.
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: