The path.resolve() method is used to resolve a sequence of path-segments to an absolute path. It works by processing the sequence of paths from right to left, prepending each of the paths until the absolute path is created. The resulting path is normalized and trailing slashes are removed as required.
If no path segments are given as parameters, then the absolute path of the current working directory is used.
path.resolve( [...paths] )
Parameters: This function accepts one parameter as mentioned above and described below:
- paths: It is a series of file paths that would be resolved together to form an absolute path. It throws a TypeError if this parameter is not a string value.
Return Value: It returns a string with absolute path.
Below programs illustrate the path.resolve() method in Node.js:
Current directory: G:\tutorials\nodejs-path-resolve G:\tutorials\nodejs-path-resolve\users\admin\readme.md G:\tutorials\nodejs-path-resolve\users\admin\readme.md G:\users\admin\readme.md
Current directory: G:\tutorials\nodejs-path-resolve G:\tutorials\nodejs-path-resolve\readme.md G:\tutorials\nodejs-path-resolve\users\files\readme.md G:\tutorials\nodejs-path-resolve\users\readme.md