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 :: pwa angular npm 
Javascript :: npm ERR! code EJSONPARSE 
Javascript :: react check if mounted 
Javascript :: js markdown to html 
Javascript :: foreach object javascript 
Javascript :: heroku scripts 
Javascript :: string to jsonobject gson 
Javascript :: using .includes for an array of objects js 
Javascript :: check if all elements in array are true javascript 
Javascript :: get closest element id jquery 
Javascript :: javascript fill array from 0 to n 
Javascript :: js convert to fraction 
Javascript :: print page in javascript 
Javascript :: jquery duplicate last table row 
Javascript :: react aws s3 npm 
Javascript :: javascript class inheritance 
Javascript :: can you call api in next.js getserverside props 
Javascript :: restfull api methods 
Javascript :: iframe reload parent page 
Javascript :: ngx toastr 
Javascript :: vue cli - Uncaught SyntaxError: Unexpected token < 
Javascript :: how to append value to input field using jquery 
Javascript :: js array to csv 
Javascript :: react useeffect avoid initial render 
Javascript :: jquery match height,jquery matchheight 
Javascript :: generate a random id 
Javascript :: jquery scroll to element id 
Javascript :: useSearchParams 
Javascript :: javascript array add 
Javascript :: async false in ajax 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =