How to read a symlink in Node.js
If you have determined that the file is a symlink try this:
fs.readlink("./mysimlink", function (err, linkString) {
// .. do some error handling here ..
console.log(linkString)
});
Confirmed as working on Linux.
You could then use fs.realpath()
to turn it into a full path. Be aware though that linkString
can be just a filename or relative path as well as a fully qualified path so you may have to get fs.realpath()
for the symlink, determine its directory part and prefix it to linkString
before using fs.realpath()
on it.