Answers for "javascript how to check if file exists on filesystem"

18

node check if file exists

const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
    // Do something
}
Posted by: Guest on May-22-2020
1

javascript file exists check

// checking existence of file synchronously
function doesFileExist(urlToFile) {
    var xhr = new XMLHttpRequest();
    xhr.open('HEAD', urlToFile, false);
    xhr.send();
     
    return xhr.status !== 404;
}
Posted by: Guest on June-30-2020

Code answers related to "javascript how to check if file exists on filesystem"

Code answers related to "Javascript"

Browse Popular Code Answers by Language