Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!