- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Introduction to Sync emptyDir() in NodeJS
This method is used to empty a directory whether it is empty or not with a sync process. If the directory is not empty, it will remove all its contents and empty it. A new empty directory is created if the directory does not exist.
dir – This is a string paramter which will hold the location of the directory structure.
Check that fs-extra is installed before proceeding; if not, install fs-exra.
You can use the following command to check whether fs-extra is installed or not.
npm ls fs-extra
Create a syncEmptyDir.js and copy-paste the following code snippet into that file.
Now, run the following command to run the following code snippet.
Code Snippet −
const fs = require('fs-extra') // Assuming the directory exists and has content fs.emptyDirSync('/tmp/dir') console.log('Empty Directory Sync Success !')
C:\Users\tutorialsPoint\> node syncEmptyDir.js Empty Directory Sync Success !
- EmptyDir() function in fs-extra - NodeJS
- Introduction to ensureFileSync() in NodeJS
- Introduction to Sequelize in NodeJS
- Sync Copy in fs-extra using NodeJS
- Sync vs Async vs Async/Await in fs-extra - NodeJS
- Introduction to Databases
- Introduction to Backtracking
- Difference between Sync and Backup
- Introduction to Backtracking Algorithms
- Introduction to Miscellaneous Problems
- Introduction to Searching Algorithms
- Introduction to Sorting Techniques
- Introduction to Greedy Algorithms
- Introduction to Dynamic Programming
- Introduction to Graph Algorithms