0
0
Node.jsframework~10 mins

Why URL parsing 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 URL class from the 'url' module.

Node.js
const { [1] } = require('url');
Drag options to blanks, or click blank then click option'
AURL
Bparse
Cformat
Dresolve
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parse' instead of 'URL' which is a function, not a class.
Trying to import the whole module without destructuring.
2fill in blank
medium

Complete the code to create a new URL object from a string.

Node.js
const myUrl = new URL([1]);
Drag options to blanks, or click blank then click option'
A'http://example.com/path?name=abc#section'
Bhttp://example.com
CurlString
DurlObject
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a variable name instead of a string literal.
Omitting quotes around the URL string.
3fill in blank
hard

Fix the error in accessing the hostname property of the URL object.

Node.js
console.log(myUrl.[1]);
Drag options to blanks, or click blank then click option'
Ahost
Borigin
Chref
Dhostname
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'host' which includes the port number.
Using 'href' which returns the full URL string.
4fill in blank
hard

Fill both blanks to extract the pathname and search parameters from the URL.

Node.js
const path = myUrl.[1];
const params = myUrl.[2];
Drag options to blanks, or click blank then click option'
Apathname
BsearchParams
Csearch
Dhash
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'search' instead of 'searchParams' which is a string, not an object.
Confusing 'hash' with query parameters.
5fill in blank
hard

Fill all three blanks to add a new query parameter and get the full updated URL string.

Node.js
myUrl.[1].append('[2]', '[3]');
console.log(myUrl.href);
Drag options to blanks, or click blank then click option'
AsearchParams
Buser
C123
Dparams
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'params' instead of 'searchParams'.
Confusing the key and value order in append.