Answers for "node check is 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'

try {
  if (fs.existsSync(path)) {
    //file exists
  }
} catch(err) {
  console.error(err)
}
Posted by: Guest on November-02-2020

Code answers related to "node check is a file exists"

Code answers related to "Javascript"

Browse Popular Code Answers by Language