0
0
Node.jsframework~5 mins

Creating and removing directories in Node.js - Quick Revision & Summary

Choose your learning style9 modes available
Recall & Review
beginner
What Node.js module do you use to create and remove directories?
You use the fs module, which provides functions like mkdir to create and rmdir or rm to remove directories.
Click to reveal answer
intermediate
How do you create a directory including any missing parent folders in Node.js?
Use fs.mkdir(path, { recursive: true }). The recursive: true option creates all missing parent directories automatically.
Click to reveal answer
intermediate
What is the difference between fs.rmdir and fs.rm when removing directories?
fs.rmdir removes empty directories only. fs.rm with { recursive: true } can remove directories with files inside.
Click to reveal answer
beginner
What happens if you try to create a directory that already exists without the recursive option?
Node.js will throw an error because the directory already exists. Using { recursive: true } prevents this error by ignoring existing directories.
Click to reveal answer
advanced
How can you remove a directory and all its contents safely in Node.js?
Use fs.rm(path, { recursive: true, force: true }). This removes the directory and everything inside it without throwing errors if the directory doesn't exist.
Click to reveal answer
Which option makes fs.mkdir create all missing parent directories?
A{ recursive: false }
B{ recursive: true }
C{ force: true }
D{ createParents: true }
Which method removes a directory only if it is empty?
Afs.mkdir
Bfs.rm with recursive
Cfs.rmdir
Dfs.unlink
What does fs.rm(path, { force: true }) do?
ARemoves a directory and ignores errors if it doesn't exist
BCreates a directory forcibly
CRemoves files only
DThrows error if directory doesn't exist
If you try to create a directory that exists without recursive option, what happens?
ADirectory is overwritten
BParent directories are created
CDirectory is ignored silently
DError is thrown
Which Node.js module provides directory creation and removal functions?
Afs
Bpath
Chttp
Dos
Explain how to create a directory and all its missing parent directories in Node.js.
Think about the option that allows creating multiple levels of folders at once.
You got /4 concepts.
    Describe the difference between removing an empty directory and removing a directory with files inside in Node.js.
    Consider which methods allow deleting directories with content and which do not.
    You got /4 concepts.