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 :: javascript.loop 
Javascript :: discord.js purge 
Javascript :: Auto increment in realtime database with javascript 
Javascript :: chart.js 
Javascript :: how to unfreeze object in javascript 
Javascript :: how to log all messages discord.js 
Javascript :: set method in javascript 
Javascript :: console log all array values node 
Javascript :: how to store variable in local storage angualur 
Javascript :: javascrip functions parameters 
Javascript :: variable name as a string in Javascript function 
Javascript :: express get port from request 
Javascript :: parse json java 
Javascript :: js infinite loop 
Javascript :: regex for ipv4 
Javascript :: javascript xmlhttprequest 
Javascript :: break loop timeout javascript 
Javascript :: Javascript: 
Javascript :: trigger jquery autocomplete on click 
Javascript :: discord js people in voice channel 
Javascript :: check if string javascript 
Javascript :: Passing Boolean values as Props in react 
Javascript :: array reverse with for loop 
Javascript :: find longest word in a string javascript 
Javascript :: javascript check number length 
Javascript :: javascript json error html 
Javascript :: setup neovim vscode jj hotkey 
Python :: suppres tensorflow warnings 
Python :: show all columns pandas 
Python :: python change recursion depth 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =