use node js to check if a json file exists
const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
// Do something
}const fs = require('fs')
const path = './file.txt'
try {
if (fs.existsSync(path)) {
//file exists
}
} catch(err) {
console.error(err)
}
const fs = require('fs')
const path = './file.txt'
//Async method
fs.access(path, fs.F_OK, (err) => {
if (err) {
console.error(err)
return
}
//file exists
})
function executeIfFileExist(src, callback) {
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
if (this.readyState === this.DONE) {
callback()
}
}
xhr.open('HEAD', src)
}
Also in JavaScript:
- firebase get current user javascript
- sleep function js
- web worker multiple data
- async reduce javascript
- vowels consonants javascript
- js queryselector names
- file ajax
- jquery steps next button event
- javascript function call with variable
- js replace all substrings
- javascript detect collision
- push item to array js
- javascript format currency
- express fingerprint
- get data attribute javascript
- Lazy loading and code splitting in Vue.js
- if i pass an object to a function is it the same object javascript
- mvc asp.net partial view from js
- jquery add input placeholder
- html button click only once
- javascript promise with ajax
- javascript get n random elements from array
- $(document).on in javascript
- conditional array element js