Node.js fs-extra pathExists() Function Last Updated : 07 Oct, 2021 Comments Improve Suggest changes Like Article Like Report The pathExists() tests whether the given file path exists or not. It uses the fs.access() under the hood. Syntax: fs.pathExists(file,callback) Parameters: This function accepts two parameters as mentioned above and described below: file: It is a string that contains the file path.callback: It will be called after the function is executed. It will either result in an error or a boolean value called exists. We can use promises in place of the callback function as well. Return value: It does not return anything. Follow the steps to implement the function: The module can be installed by using the following command: npm install fs-extra After the installation of the module you can check the version of the installed module by using this command: npm ls fs-extra Create a file with the name index.js and require the fs-extra module in the file using the following command: const fs = require('fs-extra'); To run the file write the following command in the terminal: node index.js Project Structure: The project structure will look like this: Example 1: index.js // Requiring module const fs = require("fs-extra"); // This file already // exists so function // will return true const file = "file.txt"; // Function call // Using callback function fs.pathExists(file, (err, exists) => { if (err) return console.log(err); console.log(exists); }); Output: This will be the console output. Example 2: index.js // Requiring module const fs = require("fs-extra"); // This file doesn't // exists so function // will return false const file = "dir/file.txt"; // Function call // Using Promises fs.pathExists(file) .then((exists) => console.log(exists)) .catch((e) => console.log(e)); Output: This will be the console output. Comment More infoAdvertise with us Next Article Node.js fs-extra pathExists() Function P pritishnagpal Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Node.js Technical Scripter 2020 NodeJS-fs-extra +2 More Similar Reads Node.js fs-extra outputJson() Function The outputJson() function writes an object to the JSON file. If the user wants to write data onto a file that doesn't exist it will be created by the function itself. outputJSON() can also be used in place of outputJson(). Syntax: fs.outputJson(file,object,options,callback) or fs.outputJSON(file,obj 3 min read Node.js fs-extra outputFile() Function The outputFile() function writes the data onto the given file. It is similar to the writeFile() function except that if the file onto which the data has to be written does not exist, it will be created by the function itself. Even if the file is located in a directory that does not exist, it will be 3 min read Node.js fs-extra remove() Function the remove() function deletes the given file or directory. All the files inside a directory are deleted. If the given file or directory does not exist the function will do nothing. Syntax: fs.remove(path,callback) Parameters: This function accepts two parameters as mentioned above and described belo 1 min read Node.js fs-extra move() Function The move() function moves a file or a directory from source to the destination specified by the user. If you want to move a file to a folder in which a file with the same name already exists, the function will overwrite the file if we have set the option of overwrite to true else it will throw an er 3 min read D3.js node.path() Function The node.path() function in d3.js is used return the shortest path between the source and destination node. Syntax: node.path(target); Parameters: This function accepts single parameter as given above and described below: target: This parameter accepts a destination node. Return Value: This function 2 min read Like