check if path exists javascript code example
Example 1: 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());
Example 2: node if path exists
const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
// Do something
}