node check if file exists
const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
// Do something
}const fs = require('fs');
let file = '../path/to/chad_warden.mpeg';
// async
const fileExists = (file) => {
return new Promise((resolve, reject) => {
fs.access(file, fs.constants.F_OK, (err) => {
err ? reject(false) : resolve(true)
});
})
}
// sync
const fileExistsSync = (file) => {
try {
fs.accessSync(file, fs.constants.R_OK | fs.constants.W_OK);
return true;
} catch (err) {
return false;
}
}
Also in JavaScript:
- fetch is not defined amazon-cognito-identity-js
- mongoose nullable
- clear input jqueyr
- js switch case greater than
- jsx full form
- npm stop react app
- js redirect page
- reusable table in react js
- sweet alert js
- jquery disable enter key submit
- how to add functionality inside js object
- how to check if 2 images are touching js
- react native init project
- closures in javascript
- nodejs include json file
- expo react native
- search a word and separate in javascript
- implicit return arrow function
- getcollectionnames
- convert json to object jackson
- convert string to datetime javascript
- check how many of a word is in a string
- js what does var mean
- javascript ascending and descending