07 / 16

How can you check if a given path is a file or a directory in Node.js?

You can use the fs.stat() method to get information about a file or directory, including whether it's a file or directory. Here's an example:

javascript
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.