Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js check file exist

import fs from 'fs';

const path = './file.txt';

try {
  if (fs.existsSync(path)) {
    //file exists
  }
} catch(err) {
  console.error(err);
}
Comment

javascript check if file exists on server

function doesFileExist(urlToFile) {
    var xhr = new XMLHttpRequest();
    xhr.open('HEAD', urlToFile, false);
    xhr.send();
     
    if (xhr.status == "404") {
        return false;
    } else {
        return true;
    }
}
Comment

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;
}
Comment

check if file exists javascript

function executeIfFileExist(src, callback) {
    var xhr = new XMLHttpRequest()
    xhr.onreadystatechange = function() {
        if (this.readyState === this.DONE) {
            callback()
        }
    }
    xhr.open('HEAD', src)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native getstream 
Javascript :: get first duv with jquery 
Javascript :: javascript loop object 
Javascript :: react native modal close when click outside 
Javascript :: run onclick function once js 
Javascript :: generate express js project 
Javascript :: javascript json stringify indented 
Javascript :: how to change the background color of html in javascript 
Javascript :: js is undefined or null 
Javascript :: mongodb sort 
Javascript :: add property to all documents mongo 
Javascript :: two array in one js 
Javascript :: how to assert element attributes in cypress 
Javascript :: laravel ajax post data to controller 
Javascript :: module is not defined eslint 
Javascript :: body-parser deprecated 
Javascript :: javascript code to calculate compound interest 
Javascript :: functional component how to add to existing array react 
Javascript :: express error middleware 
Javascript :: swap in javascript 
Javascript :: reducer in react example 
Javascript :: window.print filename 
Javascript :: first letter uppercase js 
Javascript :: convert Float64Array to array in js 
Javascript :: node js currency format 
Javascript :: netmask /24 
Javascript :: pass data from child to parent react 
Javascript :: https error response with status 200 angular 
Javascript :: status 502 bad api gateway error solution for aws lambda 
Javascript :: javascript append array to array 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =