Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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!");
    }
  });
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #create #file #exists #nodejs
ADD COMMENT
Topic
Name
7+6 =