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 :: redirect to given link jquer 
Javascript :: crypto node 
Javascript :: export html table data to excel using javascript 
Javascript :: mongoose delete request 
Javascript :: prevent default jquery 
Javascript :: jquery wp disable 
Javascript :: jshint esversion 6 
Javascript :: Creating a Proxy Object 
Javascript :: ajax form picture upload 
Javascript :: onclick inline function react 
Javascript :: cannot find module @babel/compat-data/data/corejs3-shipped-proposals 
Javascript :: check if all elements in array are true javascript 
Javascript :: Javascript Regex for non-negative numbers 
Javascript :: change alt text javascript 
Javascript :: us phone number regex 
Javascript :: window.location.href 
Javascript :: change file name in node.js 
Javascript :: js obj getting count of properties 
Javascript :: how to downgrade node version 
Javascript :: jquery ajax get response code 
Javascript :: how to validate file type in jquery 
Javascript :: click anchor tag using jquery 
Javascript :: how to pause js execution 
Javascript :: check if url is http or https javascript 
Javascript :: extract value from array of objects javascript 
Javascript :: saveas angular 6 
Javascript :: miles to metres js 
Javascript :: How to hthe amount of users online in discordjs 
Javascript :: js includes 
Javascript :: using bootstrap in react 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =