Languages
[Edit]
EN

Node.js - check if path is file

0 points
Created by:
Dirask Admin - MR
1340

In this article, we would like to show you how to check that path is a file in Node.js.

Quick solution:

const fs = require('fs');

fs.lstatSync(pathToCheck).isFile();

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').isFile());           // false
console.log(fs.lstatSync('my_directory/file.txt').isFile());  // true

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