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.

Advertisements
 const isDir = fs.statSync(path).isDirectory();
See also  Install NodeJS on Ubuntu 19.04

Leave a Reply

Your email address will not be published.

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