Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Node.js: Check if file is an symbolic link when iterating over directory with 'fs'

Node.js: Check if file is an symbolic link when iterating over directory with 'fs'

Problem

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?

Problem courtesy of: james_womack

Solution

I'm not certain what you mean by a file being an 'alias', but if you mean a symbolic link you can use fs.lstat and then call stats.isSymbolicLink() on the fs.Stats object that's passed into your lstat callback.

Solution courtesy of: JohnnyHK

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Node.js: Check if file is an symbolic link when iterating over directory with 'fs'

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×