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

Przemyslaw Mazur
PLUS
Przemyslaw Mazur
Courses Plus Student 9,296 Points

How does the browser know that the text we type in the form field is a username.

I know there is a method used on it. I mean var username = request.url.replace("/", "");. Shouldn't it just replace the / symbol with an empty string and why it doesn't set the username variable to the whole url including "http://port-3000-2rmzgrlbw8.treehouse-app.com/"

1 Answer

Steven Parker
Steven Parker
231,269 Points

The "replace("/", "")" method does replace the / symbol with an empty string.

If I understand the other question, the rest of the URL is removed because a header is being constructed that only contains a relative path.

It gets it from the html attribute. So if I gave my search input the name attribute of cook and hit search...

<input type="text" placeholder="Enter a Treehouse username" id="book" name="cook">

I would get something like this:

cook=pizza