Supervisor is a package for Node.js that monitors files in your app directory for modifications and reloads the app when a modification occurs.
This script interprets symbolic links as regular files and logs out a warning. I would like to fork Supervisor so that either this can be fixed entirely or that a more descriptive warning is produced.
How can I use the File System module of Node.js to determine if a given file is really an symbolic link?
The fs. existsSync() method allows you to check for the existence of a file by tracing if a specified path can be accessed from the current directory where the script is executed. It returns true when the path exists and false when it's not.
Any Node. Js version. const fs = require("fs"); let path = "/path/to/something"; fs. lstat(path, (err, stats) => { if(err) return console.
stat() does handle links, it just handles them differently - it follows the link and tells you about the file that it points to (which, as wich points out, is oftentimes what you want). You use stat() when you want links to behave in the "normal way", i.e. as the file they point at.
You can use fs.lstat
and then call statis.isSymbolicLink()
on the fs.Stats
object that's passed into your lstat callback.
fs.lstat('myfilename', function(err, stats) { console.log(stats.isSymbolicLink()); });
Seems like you can use isSymbolicLink()
const files = fs.readdirSync(dir, {encoding: 'utf8', withFileTypes: true}); files.forEach((file) => { if (file.isSymbolicLink()) { console.log('found symlink!'); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With