EN
Node.js - check if path is directory
0
points
In this article, we would like to show you how to check that path is a directory in Node.js.
Quick solution:
const fs = require('fs');
fs.lstatSync(pathToCheck).isDirectory();
Practical example
Projects structure
Project/
|
+-- my_directory/
| |
| +-- file.json
|
+-- my_script.js
my_script.js
const fs = require('fs');
console.log(fs.lstatSync('my_directory').isDirectory()); // true
console.log(fs.lstatSync('my_directory/file.txt').isDirectory()); // false