The fs.realPath() method is used to compute the canonical pathname of the given path. It does so by resolving the
.. and the symbolic links in the path.
fs.realpath( path, options, callback )
Parameters: This method accept three parameters as mentioned above and described below:
- path: It holds the path of the directory that has to be resolved. It can be a String, Buffer or URL.
- options: It is an string or object that can be used to specify optional parameters that will affect the operation. It has one optional parameter:
- encoding: It is a string which defines the encoding of the resolved path.
- callback: It is the function that would be called when the method is executed.
- err: It is an error that would be thrown if the operation fails.
- resolvedPath: It is string or buffer that represents the resolved path.
Below examples illustrate the fs.realPath() method in Node.js:
Example 1: This example uses fs.realPath() method to get the canonical paths of the given path.
Current Directory Path: G:\tutorials\nodejs-fs-realPath Two directories up resolved path is: G:\ One directory up resolved path is: G:\tutorials
Example 2: This example uses fs.realPath() method to demonstrate the different encoding type.
The resolved path is: G:\tutorials The resolved path is: 473a5c7475746f7269616c73 The resolved path is: RzpcdHV0b3JpYWxz
- Nodejs | Automatic restart NodeJs server with nodemon
- Nodejs console.timeLog() Method
- Nodejs | DNS
- Web-Socket in NodeJS
- Nodejs | DNS | setServers()
- Nodejs | Jimp
- Nodejs | GM roll() Function
- Nodejs | GM gamma() Function
- Nodejs | GM border() Function
- Nodejs | GM gaussian() Function
- Nodejs | GM bordercolor() Function
- Nodejs | GM crop() Function
- Nodejs | GM despeckle() Function
- Nodejs | GM threshold() Function
- Nodejs | GM segment() Function
- Nodejs | GM quality() Function
- Nodejs | GM transparent() Function
- Nodejs | GM flip() Function
- Nodejs | GM resize() Function
- Nodejs | GM motionBlur() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.