I want to read a symlink, and get the details of the link itself, not the contents of the linked file. How do I do that in Node, in a cross-platform way?
I can detect symlinks easily using lstat
, no problem. Once I know the path of the file, and that it is a symlink though, how can I read it? fs.readFile
always reads the target file, or throws an error for reading a directory for links to directories.
There is a fs.constants.O_SYMLINK
constant, which in theory solves this on OSX, but it seems to be undefined on both Ubuntu & Windows 10.