Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

create file if not exists nodejs

function writeToFile() {
  fs.open(filepath,'r',function(fileExists, file) {
    if (fileExists) {

      fs.writeFile( filepath, JSON.stringify(prodDetail), (err) => {
        if (err) console.error(err)
        console.log('Data written')
      });

    } else {
      console.log("File already exists!");
    }
  });
}
Comment

nodejs fs create file if not exists

fs.exists(filename, function(exists) {
  if(exists) {
    // Create a file
  }
  else {
    console.log("Deny overwrite existing", filename);
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript class methods 
Javascript :: javascript move element to coordinates 
Javascript :: switch alert 
Javascript :: js array from 
Javascript :: react webpack.config.js 
Javascript :: javascript get all days of week 
Javascript :: select field in react native 
Javascript :: js json_encode pretty 
Javascript :: open modal useState 
Javascript :: base64 to image nodejs 
Javascript :: regex in mongo query 
Javascript :: react native safeareaview 
Javascript :: import library react js 
Javascript :: javascript DOM query selector 
Javascript :: get value of hidden type field 
Javascript :: express receive post data 
Javascript :: get position of element relative to document 
Javascript :: react native vector icons not working 
Javascript :: javascript get string from array with space between 
Javascript :: angular router outlet 
Javascript :: Handle click outside a component in react with hooks 
Javascript :: select distinct on expressions must match initial order by expressions django 
Javascript :: moment get timestamp 
Javascript :: Could not find a production build in the 
Javascript :: aes 256 nodejs 
Javascript :: get url parameters javascript 
Javascript :: array asociativo multidimensional javascript 
Javascript :: create node server 
Javascript :: anagram program in javascript 
Javascript :: how to remove first character from string in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =