0
0
Node.jsframework~10 mins

path.join for cross-platform paths in Node.js - Interactive Code Practice

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

Complete the code to import the path module in Node.js.

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

Complete the code to join directory 'folder' and file 'file.txt' into a path.

Node.js
const fullPath = path.[1]('folder', 'file.txt');
Drag options to blanks, or click blank then click option'
Ajoin
Bresolve
Cbasename
Ddirname
Attempts:
3 left
💡 Hint
Common Mistakes
Using resolve which resolves to an absolute path.
Using basename which returns the last part of a path.
3fill in blank
hard

Fix the error in the code to join 'dir' and 'file.txt' correctly.

Node.js
const fullPath = path.[1]('dir', 'file.txt');
Drag options to blanks, or click blank then click option'
Aresolve
Bbasename
Cjoin
Ddirname
Attempts:
3 left
💡 Hint
Common Mistakes
Concatenating path strings manually with slashes.
Using basename or dirname incorrectly.
4fill in blank
hard

Fill both blanks to join 'folder', 'subfolder', and 'file.txt' into a path.

Node.js
const fullPath = path.[1]('folder', [2], 'file.txt');
Drag options to blanks, or click blank then click option'
Asubfolder
Bjoin
Cresolve
Dbasename
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping method and folder name positions.
Using resolve instead of join.
5fill in blank
hard

Fill all three blanks to join 'home', 'user', and 'docs' into a path.

Node.js
const fullPath = path.[1]('[2]', '[3]', 'docs');
Drag options to blanks, or click blank then click option'
Aresolve
Bjoin
Cuser
Dhome
Attempts:
3 left
💡 Hint
Common Mistakes
Using resolve instead of join.
Swapping folder names or missing quotes.