0
0
Node.jsframework~10 mins

Parsing query strings 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 Node.js module for parsing query strings.

Node.js
const querystring = require('[1]');
Drag options to blanks, or click blank then click option'
Aquerystring
Burl
Chttp
Dfs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'url' instead of 'querystring' for parsing query strings.
Trying to import a non-existent module.
2fill in blank
medium

Complete the code to parse a query string into an object.

Node.js
const parsed = querystring.[1]('name=alice&age=25');
Drag options to blanks, or click blank then click option'
Astringify
Bencode
Cparse
Dformat
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'stringify' which converts an object to a query string.
Using 'format' which is unrelated here.
3fill in blank
hard

Fix the error in the code to correctly parse the query string.

Node.js
const parsed = querystring.parse('name=alice&age=[1]');
Drag options to blanks, or click blank then click option'
Atwenty five
B25
Cage=25
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Putting a phrase with spaces without encoding.
Including key names inside the value.
4fill in blank
hard

Fill both blanks to convert an object to a query string and log it.

Node.js
const obj = { name: 'bob', city: 'nyc' };
const str = querystring.[1](obj);
console.log([2]);
Drag options to blanks, or click blank then click option'
Astringify
Bobj
Cstr
Dparse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parse' instead of 'stringify' to convert object to string.
Logging the object instead of the string.
5fill in blank
hard

Fill all three blanks to parse a query string, update a value, and convert it back to a string.

Node.js
let params = querystring.[1]('color=red&size=medium');
params.[2] = 'large';
const updatedStr = querystring.[3](params);
Drag options to blanks, or click blank then click option'
Aparse
Bsize
Cstringify
Dcolor
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to update a property that doesn't exist.
Mixing up parse and stringify methods.