Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

nodejs fs delete file

const fs = require('fs')

const path = './file.txt'

try {
  fs.unlinkSync(path)
  //file removed
} catch(err) {
  console.error(err)
}
Comment

node delete file folder

const fs = require('fs');
    const Path = require('path');

    const deleteFolderRecursive = function (directoryPath) {
    if (fs.existsSync(directoryPath)) {
        fs.readdirSync(directoryPath).forEach((file, index) => {
          const curPath = path.join(directoryPath, file);
          if (fs.lstatSync(curPath).isDirectory()) {
           // recurse
            deleteFolderRecursive(curPath);
          } else {
            // delete file
            fs.unlinkSync(curPath);
          }
        });
        fs.rmdirSync(directoryPath);
      }
    };
Comment

PREVIOUS NEXT
Code Example
Javascript :: set port in react app 
Javascript :: npx for windows 
Javascript :: object to url params js 
Javascript :: how to reload the same page using javascript 
Javascript :: how to use jquery in chrome dev tools 
Javascript :: how to check if selector exists or is present puppeteer 
Javascript :: how to run vue js project on different port 
Javascript :: how to sort string aray in ts 
Javascript :: react native hide stack navigator title 
Javascript :: godot destroy node 
Javascript :: js scrolling in div 
Javascript :: fibonacci sequence in javascript using for loop 
Javascript :: python print pretty json 
Javascript :: $(...).autocomplete is not a function 
Javascript :: sanity install 
Javascript :: javascript median of array 
Javascript :: javascript sort by numerical value 
Javascript :: Hide a div on clicking outside it with jquery 
Javascript :: javascript trim newline 
Javascript :: js key is pressed 
Javascript :: remove last char from string javascript 
Javascript :: how to install font-awesome 
Javascript :: js event listener url change 
Javascript :: find difference between string js 
Javascript :: self invoked function javascript 
Javascript :: creating new react app 
Javascript :: jquery reset form 
Javascript :: how prevent copy paste input react 
Javascript :: cut text if too long javascript 
Javascript :: vimeo regez video id 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =