node js check is file code example
Example 1: node check if file exists
const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
// Do something
}
Example 2: check if path is folder js
var fs = require('fs');
var stats = fs.statSync("c:\\dog.jpg");
console.log('is file ? ' + stats.isFile());
var stats = fs.statSync("c:\\demo");
console.log('is directory ? ' + stats.isDirectory());