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 :: text to Speech in javascript code 
Javascript :: javascript check if date is less than today 
Javascript :: moment check valid date 
Javascript :: fast xml parser nodejs 
Javascript :: javascript remove last character from string 
Javascript :: window.history.pushstate typescript 
Javascript :: javascript loop thrugh array 
Javascript :: how to set view engine in express 
Javascript :: how send to another page by router in vuejs 
Javascript :: Print a number with commas as thousands separators in JavaScript 
Javascript :: react native spinner 
Javascript :: jquery grid disable sorting 
Javascript :: javascript make beep sound 
Javascript :: angular form set value without fire event 
Javascript :: js json download 
Javascript :: box shadow javascript style change 
Javascript :: once content is loaded run part of code 
Javascript :: string to JSONobject + android 
Javascript :: Jquery Scroll on div using anchor tag is not Working properly 
Javascript :: missing from-clause entry for table sequelize limit 
Javascript :: jquery set max attribute value 
Javascript :: for each element in obj js 
Javascript :: javascript checkbox checked event 
Javascript :: how to filter array objesct in express node js 
Javascript :: javascript with html 
Javascript :: javascript check if value exists in array of objects 
Javascript :: node fs get directory creation date 
Javascript :: javascript number to words 
Javascript :: remove all spaces javascript 
Javascript :: js rect collision 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =