The fs.promises.link() method is an inbuilt application programming interface of the fs.promises class which is used to make a new name for a file.
Parameters: This method accept two parameters as mentioned above and described below:
- existing_path: It is a required parameter specifies a string/URL/Buffer which denotes the existing path of the file.
- new_path: It is a required parameter specifies a string/URL/Buffer which denotes the new path for the file.
Return Value: It returns a promise. If the linking is successful the promise is resolved with no value, otherwise rejected with an error object.
Below examples illustrate the use of fs.promises.link() method in Node.js:
(node:5052) ExperimentalWarning: The fs.promises API is experimental linked successfully
(node:11936) ExperimentalWarning: The fs.promises API is experimental failed to link!
Note: The above program will compile and run by using the
node filename.js command and use the file_path correctly.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.