Skip to content

Check if a path is file or directory in Node.js

To find out if a file path is a file or a directory we can use fs.statSync(path).isDirectory() method. It returns a boolean, true if the path is a directory.

 const isDir = fs.statSync(path).isDirectory();

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.