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 Express Basics Deeper into Routing with Express Solution: Clearing Cookies and Redirecting

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

/goodbye

Any reason for putting the /goodbye in the action attribute and even while posting data. I tried using just the '/', it worked. So, is there any reason behind that. Won't the app will generate an error, as we do not have any accurate path as /goodbye does not exist?

1 Answer

Caleb Kemp
Caleb Kemp
12,755 Points

Maybe I'm confused, at 0:45 he adds a '/goodbye' route to the app.js file, so, maybe you didn't notice that?

On the other hand, you might say, I can process this data using the route I already have working, why do I need to add more routes? Now, while it is true, you can have your program perform a massive amount of functionality with one just one route, having most of your functionality in just one route gives you less granular control over the application. For example, Imagine having a calculator, and every time you pushed the number "4", it processed (4*4 +7-3/2.5^3). Well, if you wanted that calculation to be performed a lot, that could be super helpful, however, don't you imagine there would be times when you would want an actual "4" when you pressed "4"? So I think you can see that having more than one button can increase the usefulness of a calculator, having more than one route can increase the functionality of your application. Hope that Helps!

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

Hi @caleb, I guess I did not clear my question, I saw that he added in the app.js, but in actual we donot have any goodbye file in our system, so where that data is getting posted, isn't that an Invalid path?

Caleb Kemp
Caleb Kemp
12,755 Points

When you submit the form using "action", "method", it will look for a route using the using method (post, get, delete, put) specified, with a route having the "action"s value. For example the form

form(action='/destroyEarth', method='delete')

will look for a "delete" method with the route "/destroyEarth". All the form cares about is that you have the route, it doesn't care if you use the information, or if the route actually matches the name of a page or file in your system.

Where is our data getting posted?

If Andrew had wanted to send data in the post request, the route would have needed to be configured to handle that Since the purpose of this route was to destroy user cookies, that wasn't needed. Hope that makes sense :smile: