Check folder exist nodejs
Check if file exist express
const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
// Do something
}
use node js to check if a json file exists javascript
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
})
use async await check file in nodejs
const fs = require('fs');
let file = '../path/to/chad_warden.mpeg';
// async
const fileExists = (file) => {
return new Promise((resolve) => {
fs.access(file, fs.constants.F_OK, (err) => {
err ? resolve(false) : resolve(true)
});
})
}
Có thể bạn đã miss một số snippets code