Challenge - 5 Problems
URL Parsing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why is URL parsing important in Node.js?
Which of the following best explains why URL parsing is important when building web applications in Node.js?
Attempts:
2 left
💡 Hint
Think about how a server knows what resource a user wants when they visit a web address.
✗ Incorrect
URL parsing breaks a web address into parts so the server can understand what is requested. This is essential for routing and handling requests properly.
❓ component_behavior
intermediate2:00remaining
What does Node.js URL parser output?
Given the following Node.js code, what will be the value of `parsedUrl.pathname`?
Node.js
import { URL } from 'url'; const myUrl = new URL('https://example.com:8080/path/name?search=test#hash'); const parsedUrl = myUrl;
Attempts:
2 left
💡 Hint
The pathname is the part of the URL after the domain and port but before query or hash.
✗ Incorrect
The pathname property contains the path section of the URL, which is /path/name in this example.
📝 Syntax
advanced2:00remaining
Identify the syntax error in URL parsing code
Which option contains a syntax error that will cause the Node.js URL parsing code to fail?
Node.js
import { URL } from 'url'; const urlString = 'http://localhost:3000/api?user=123';
Attempts:
2 left
💡 Hint
Remember how to properly create a new instance of a class in JavaScript.
✗ Incorrect
Option A misses the new keyword, which is required to create a new URL object instance.
❓ state_output
advanced2:00remaining
What is the output of URL searchParams manipulation?
What will be the output of the following code snippet?
Node.js
import { URL } from 'url'; const myUrl = new URL('https://example.com?name=alice&age=30'); myUrl.searchParams.set('age', '31'); myUrl.searchParams.append('city', 'NY'); console.log(myUrl.search);
Attempts:
2 left
💡 Hint
Setting a parameter replaces its value; appending adds a new parameter.
✗ Incorrect
The set method updates the 'age' parameter to '31'. The append method adds a new 'city' parameter. So the search string includes all three.
🔧 Debug
expert2:00remaining
Why does this URL parsing code throw an error?
Consider this code snippet. Why does it throw a TypeError?
Node.js
import { URL } from 'url'; const base = 'http://example.com'; const relative = '/path'; const myUrl = new URL(relative); console.log(myUrl.href);
Attempts:
2 left
💡 Hint
Think about how the URL constructor handles relative URLs.
✗ Incorrect
The URL constructor requires a base URL when given a relative URL string. Without it, it throws a TypeError.