0
0
Node.jsframework~10 mins

Why path handling matters in Node.js - Test Your Understanding

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 path module.

Node.js
const path = require('[1]');
Drag options to blanks, or click blank then click option'
Apath
Bfs
Chttp
Durl
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fs' or 'http' instead of 'path' in require.
Forgetting to use quotes around the module name.
2fill in blank
medium

Complete the code to join directory and file name into a path.

Node.js
const fullPath = path.[1]('folder', 'file.txt');
Drag options to blanks, or click blank then click option'
Aresolve
Bbasename
Cjoin
Dextname
Attempts:
3 left
💡 Hint
Common Mistakes
Using basename which returns the last part of a path.
Using extname which returns the file extension.
3fill in blank
hard

Fix the error in the code to get the file extension.

Node.js
const ext = path.[1]('index.html');
Drag options to blanks, or click blank then click option'
Aextname
Bbasename
Cdirname
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using basename which returns the file name.
Using dirname which returns the directory path.
4fill in blank
hard

Fill both blanks to get the directory name and base file name from a path.

Node.js
const dir = path.[1]('/home/user/file.txt');
const base = path.[2]('/home/user/file.txt');
Drag options to blanks, or click blank then click option'
Adirname
Bextname
Cbasename
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up basename and dirname.
Using extname instead of basename.
5fill in blank
hard

Fill all three blanks to normalize a path, get its absolute path, and extract the extension.

Node.js
const normalized = path.[1]('folder//subfolder/../file.txt');
const absolute = path.[2](normalized);
const extension = path.[3](absolute);
Drag options to blanks, or click blank then click option'
Anormalize
Bresolve
Cextname
Dbasename
Attempts:
3 left
💡 Hint
Common Mistakes
Using basename instead of extname for extension.
Skipping normalization before resolving.