Answers for "nodejs fs, check if a file exists"

18

node check if file exists

const fs = require("fs"); // Or `import fs from "fs";` with ESM
if (fs.existsSync(path)) {
    // Do something
}
Posted by: Guest on May-22-2020
0

use node js to check if a json file exists

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
})
Posted by: Guest on November-02-2020

Code answers related to "nodejs fs, check if a file exists"

Code answers related to "Javascript"

Browse Popular Code Answers by Language