0
0
Node.jsframework~10 mins

Creating and removing directories in Node.js - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Node.js module for working with the file system.

Node.js
const fs = require('[1]');
Drag options to blanks, or click blank then click option'
Afs
Bhttp
Cpath
Dos
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' or 'os' instead of 'fs'.
Forgetting to require the module before using it.
2fill in blank
medium

Complete the code to create a new directory named 'myFolder' synchronously.

Node.js
fs.[1]Sync('myFolder');
Drag options to blanks, or click blank then click option'
AreadFile
Bmkdir
Creaddir
DwriteFile
Attempts:
3 left
💡 Hint
Common Mistakes
Using asynchronous methods without callbacks.
Using methods unrelated to directory creation.
3fill in blank
hard

Fix the error in the code to remove the directory named 'oldFolder' synchronously.

Node.js
fs.[1]Sync('oldFolder');
Drag options to blanks, or click blank then click option'
Aremove
Bunlink
Crm
Drmdir
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unlink' which is for files, not directories.
Using 'remove' which is not a valid fs method.
4fill in blank
hard

Fill both blanks to create a directory 'newDir' only if it does not exist.

Node.js
if (!fs.existsSync('newDir')) {
  fs.[1]Sync('newDir', { [2]: true });
}
Drag options to blanks, or click blank then click option'
Amkdir
Brmdir
Crecursive
Dforce
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rmdir' instead of 'mkdir'.
Using 'force' option which does not exist here.
5fill in blank
hard

Fill all three blanks to remove a directory 'tempDir' and all its contents synchronously.

Node.js
fs.[1]Sync('tempDir', { [2]: true, [3]: true });
Drag options to blanks, or click blank then click option'
Armdir
Brecursive
Cforce
Drm
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'rmdir' which cannot remove non-empty directories without options.
Omitting 'force' option causing errors if files are protected.