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

13,655 Points

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.


1 Answer

Steven Parker
Steven Parker
217,456 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.