Languages
[Edit]
EN

Node.js - check if path is directory

0 points
Created by:
Kia-H
546

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

Alternative titles

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

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