-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Section 3 Parsing Query String shows a weird queryStringObject #19
Comments
// Dependencies
const http = require("http");
const url = require("url");
// Get the query string as an object
const queryStringObject = parsedUrl.query;
The reason is that based on the Node.js documentation: In order to workaround this, you need to stringify and then parse the queryStringObject as follows: const queryString = JSON.stringify(parsedUrl.query, null, 4)
const queryStringParsed = JSON.parse(queryString) This way, you can get rid of the null prototype attached to the "queryString" |
For me, the console message shows up if I use a path without a query string, but not if I include a query string. So for example, if I type Any idea why that might be? I've tried the code both as it was explained in the video, as well as with the JSON.stringify and JSON.parse mentioned above. Both give the same result (meaning both don't work if I include a query string in my URL). Instead I see |
This is code I use (same as in the masterclass, except for the const instead of var)
Whenever I run the code, and visit the URL
http://localhost:3000/foo?fizz=buzz
or run cURL on it, I get the console log asRequest received on path: foo with method: get and this query string: [Object: null prototype] { fizz: 'buzz' }
Why do I get a
[Object: null prototype]
inside the log?The text was updated successfully, but these errors were encountered: