Recall & Review
beginner
What is the purpose of the URL class in Node.js?The URL class helps to easily parse, manipulate, and format URLs by breaking them into parts like protocol, hostname, pathname, query, and more.Click to reveal answer
beginner
How do you create a new URL object for parsing a web address?
Use the syntax: <code>const myUrl = new URL('https://example.com/path?name=value');</code> This creates an object representing the URL.Click to reveal answer
beginner
Which property of the URL object gives you the domain name?
The
hostname property returns the domain name part of the URL, like 'example.com'.Click to reveal answer
intermediate
How can you access the query parameters from a URL object?
Use the
searchParams property, which provides methods like get() to read query parameters easily.Click to reveal answer
beginner
What method would you use to convert a URL object back to a string?
Use the
toString() method or simply use the URL object in a string context to get the full URL string.Click to reveal answer
Which property of the URL object contains the path after the domain?
✗ Incorrect
The
pathname property holds the path part of the URL, like '/path/to/page'.How do you get the value of a query parameter named 'id' from a URL object?
✗ Incorrect
Use
searchParams.get('id') to retrieve the value of the 'id' query parameter.What will
new URL('https://example.com:8080').port return?✗ Incorrect
The
port property returns the port number specified in the URL, here '8080'.Which constructor is used to create a URL object in Node.js?
✗ Incorrect
The standard way is to use
new URL() to create a URL object.If you want to change the protocol of a URL object, which property do you modify?
✗ Incorrect
The
protocol property holds the scheme like 'http:' or 'https:' and can be changed.Explain how to parse a URL string and access its hostname and pathname using the URL class.
Think about creating a new URL and then reading its parts.
You got /3 concepts.
Describe how to read and modify query parameters using the URL class in Node.js.
Focus on the searchParams methods.
You got /3 concepts.