Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a Simple Dynamic Site with Node.js HTTP Methods and Headers Dealing with the POST Body

Jonathan Leon
Jonathan Leon
18,813 Points

I did it this way without querystring what do you think?

            request.on("data", function(postBody) {

          //extract the username
            var username =   postBody.toString().replace("username=",""); 

            //redirect to the username

            request.url = "/"+username;


1 Answer

Very good, jump on to the international stage!!

// returns
{ foo: 'bar', baz: ['qux', 'quux'], corge: '' }

// Suppose gbkDecodeURIComponent function already exists,
// it can decode `gbk` encoding string
querystring.parse('w=%D6%D0%CE%C4&foo=bar', null, null,
  { decodeURIComponent: gbkDecodeURIComponent })
// returns
{ w: 'δΈ­ζ–‡', foo: 'bar' }

Amazingly enough. https://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end

the international encoding can be parsed because querystring is a deserializer that can parse other encoding entypes besides utf-8. Nice huh!!!

Turn that tribal gibberish into digital anthology!