Challenge - 5 Problems
Path Handling Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why use the path module in Node.js?
Why is it important to use Node.js's
path module instead of simple string concatenation when working with file paths?Attempts:
2 left
💡 Hint
Think about how file paths look different on Windows and Unix systems.
✗ Incorrect
The path module automatically uses the correct path separator for the operating system, avoiding bugs caused by manual string concatenation.
❓ component_behavior
intermediate2:00remaining
What does path.join() output?
Given this code, what is the output of
console.log(fullPath) on a Unix system?Node.js
const path = require('path'); const fullPath = path.join('/home/user', 'docs', 'file.txt'); console.log(fullPath);
Attempts:
2 left
💡 Hint
On Unix, the path separator is a forward slash.
✗ Incorrect
path.join combines path segments using the correct separator for the OS. On Unix, it uses /.
🔧 Debug
advanced2:00remaining
Why does this path cause an error on Windows?
What error will this code cause on Windows and why?
Node.js
const path = require('path'); const filePath = '/user/docs\file.txt'; console.log(path.normalize(filePath));
Attempts:
2 left
💡 Hint
Consider how
path.normalize treats mixed slashes.✗ Incorrect
path.normalize converts all slashes to the OS default. Mixed slashes are allowed but normalized.
❓ state_output
advanced2:00remaining
What is the value of 'ext' after running this code?
What is the value of the variable
ext after this code runs?Node.js
const path = require('path'); const fileName = 'archive.tar.gz'; const ext = path.extname(fileName);
Attempts:
2 left
💡 Hint
Think about how
path.extname treats multiple dots.✗ Incorrect
path.extname returns the substring from the last dot to the end.
📝 Syntax
expert2:00remaining
Which option causes a syntax error?
Which of these code snippets will cause a syntax error when importing the
path module in Node.js ES modules?Attempts:
2 left
💡 Hint
Consider the difference between CommonJS and ES module syntax.
✗ Incorrect
In ES modules, require is not defined, so using it causes a syntax error.