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?✗ Incorrect
The option
{ recursive: true } tells Node.js to create all missing parent directories.Which method removes a directory only if it is empty?
✗ Incorrect
fs.rmdir removes empty directories only.What does
fs.rm(path, { force: true }) do?✗ Incorrect
The
force: true option ignores errors if the directory or file does not exist.If you try to create a directory that exists without recursive option, what happens?
✗ Incorrect
Node.js throws an error if the directory exists and recursive option is not used.
Which Node.js module provides directory creation and removal functions?
✗ Incorrect
The
fs module handles file system operations including directories.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.