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 :: how to make background image move mmousemove jquery 
Javascript :: regex validate double with 2 decimals 
Javascript :: nodemon compile typescript and execute js file 
Javascript :: stuck at "resolving packages" 
Javascript :: como saber la resolucion de una ventana con javascript 
Javascript :: is intersectionobserver supported in browser 
Javascript :: background transparent react native 
Javascript :: jquery einbinden in js 
Javascript :: find vowel & consonants in a string java script 
Javascript :: javascript get random character from string 
Javascript :: javascript leap year 
Javascript :: javascript get data attribute of selected option 
Javascript :: nextjs x tailwind 
Javascript :: datatable row color 
Javascript :: how to change styles when element comes into view 
Javascript :: how to create a random 2d vector in js 
Javascript :: if checkbox is checked 
Javascript :: convert hex to decimal javascript 
Javascript :: tagname js 
Javascript :: exit program js 
Javascript :: base64 PayloadTooLargeError: request entity too large 
Javascript :: react absolute import 
Javascript :: create react app with tailwind 
Javascript :: how to set text for label in jquery 
Javascript :: loop through object element names javascript 
Javascript :: js vanilla when i remove one object it removes all of them 
Javascript :: javascript format date yyyy-mm-dd 
Javascript :: get value of element html js 
Javascript :: populate dropdown with a variable 
Javascript :: pass array of strings to match in str.replace 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =