Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node js delete folder with files

const fs = require('fs');

// directory path
const dir = 'temp';

// delete directory recursively
try {
    fs.rmdirSync(dir, { recursive: true });

    console.log(`${dir} is deleted!`);
} catch (err) {
    console.error(`Error while deleting ${dir}.`);
}
Comment

fs node delete folder

const fs = require('fs');

fs.rmSync(folderPath, { recursive: true })
Comment

how to delete a folder in node js

//DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. 
//Use fs.rm(path, { recursive: true }) instead
fs.rm(path, { recursive: true })
Comment

how to delete a folder using node js

fs.unlink('./node/myText.txt',function(){
    fs.rmdir('node');
});
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 :: javascript voice reader 
Javascript :: a-z array javascript 
Javascript :: remove tr in table jquery 
Javascript :: javascript stop setinterval 
Javascript :: setpresence discord.js 
Javascript :: react clear form after save 
Javascript :: document get element by tag 
Javascript :: write in utf8 fs 
Javascript :: how to get all elements with same class in jquery 
Javascript :: wp_enqueue_script bootstrap 
Javascript :: javascript change url hash 
Javascript :: moment format date dd/mm/yyyy 
Javascript :: javascript get string between two characters 
Javascript :: js date of yesterday 
Javascript :: get current page name in javascript 
Javascript :: remove quotes from array javascript 
Javascript :: javascript string into substrings of length 
Javascript :: show and hide div tag based on checkbox selection using jquery 
Javascript :: selected option attribute jquery 
Javascript :: add style javascript 
Javascript :: how to check if file upload is empty jquery 
Javascript :: onEnter input field react 
Javascript :: clz32() js 
Javascript :: jquery scroll to top of div 
Javascript :: close exit app react native 
Javascript :: js shuffle array 
Javascript :: how to record screen using js 
Javascript :: pagecontrol 
Javascript :: how to let a function execute after 5 seconds javascript 
Javascript :: loop on objects js 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =