Languages
[Edit]
EN

Node.js - check if path is directory

0 points
Created by:
Kia-H
396

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

Node.js - file system module

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join