Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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)
}
Comment

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
})
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript how to check if object property exists 
Javascript :: javascript newline in alert 
Javascript :: get id by this jquery 
Javascript :: electron main.js template 
Javascript :: download text file javascript 
Javascript :: .env file node js 
Javascript :: mongoose custom object schema 
Javascript :: javascript classlist 
Javascript :: inline if else javascript 
Javascript :: javascript check if number is multiple of 3 
Javascript :: add month date now javascript 
Javascript :: for of array javascript 
Javascript :: assign key and value to object 
Javascript :: DataTypes Time sequelize 
Javascript :: two decimel javascript 
Javascript :: get document jquery 
Javascript :: toast in react native 
Javascript :: dropzone on success all files 
Javascript :: regex date yyyy-mm-dd 
Javascript :: node js timestamp format 
Javascript :: insert image in react 
Javascript :: how to validate a string using regular expression in javascript 
Javascript :: ecmascript 7 getmonth as 2 digits 
Javascript :: jquery remove child 1 elemtn 
Javascript :: javascript array concat spread operator 
Javascript :: discord.js messageDelete 
Javascript :: how to delete a cookie in js 
Javascript :: document.getElementByClass is not a function 
Javascript :: node fs exists 
Javascript :: android force date inside RecyclerView to re render 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =