First of all, what does link even mean? Linking in this case, is creating a new path to a existing file. If the path already exists than it will not be overwritten.
The difference between these two functions in the Filestream module has to do with the synchronicity of the functions and the number of parameters each function allows. To begin, fs.link is asynchronous which accepts 3 parameters. The first parameter is the existing path to a file, the second parameter is a new path to the same file and the third parameter is a callback function.
A very simple example of this is
var fs = require(‘fs’);
fs.link(‘/sathia/helloWorld’, ‘/sathia/byeWorld’, function(err) {
if(err){
return console.log(err);
}
});
fs.linkSync on the other hand is synchronous and accepts 2 parameters which include the existing path to the file and the new path of the file.
A very simple example of this is similiar to above without the callback function.
var fs = require(‘fs’);
fs.link(‘/sathia/helloWorld’, ‘/sathia/byeWorld’){
console.log(“Path has successfully been changed”);
}