check file with fs 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: how to check if a folder exists in node js
const fs = require("fs")
fs.access("./directory-name", function(error) {
if (error) {
console.log("Directory does not exist.")
} else {
console.log("Directory exists.")
}
})