I've seen some of the answers here like this one, but due to my reputation, I can't comment.
The problem is somehow the results show me the wrong one. It all outputs the file exists!
even though it does not really exists.
function doesFileExist (urlToFile) {
const xhr = new XMLHttpRequest()
xhr.open('HEAD', urlToFile, false)
xhr.send()
return console.log(xhr.status == 200 ? 'File exists' : 'File does not exist')
}
It outputs:
File Exists