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

Why not addEventListener on the submit button that directs to the link?

Trying to understand why we can't just add an addEventListener on the submit button such that when it's 'click'ed it executes a command to the appropriate link based on the .value in the id="username" input field? I get that node.js doesn't really have document command so the document.addEventListener(.... code wouldn't really work, but surely there has to be an equivalent library of commands in node.js.

I am asking this from a front-end developer perspective. I realize this probably shows my lack of fundamental understanding in how the front vs backend operates.

https://teamtreehouse.com/library/dealing-with-the-post-body#questions

1 Answer

Steven Parker
Steven Parker
230,231 Points

The back end has no direct interface with the user, so the document object with all its interface methods (like addEventListener) only exists in the front end. The back end doesn't get any direct notification of a button click, but if the button submits a form then it will get the package of data containing all the form information.

Handling that package of data (the "POST body") is what is being discussed in the video.