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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Xiaoxuan Wang](https://secure.gravatar.com/avatar/ae717db0b55410a3666e40d43079258f?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Xiaoxuan Wang
4,590 PointsDifferences between Homeroute and Userroute
Hi guys,
I've confusing about homeroute and userroute through this course, though finished the code mechanically. Since there seems barely differences of using either of them showed in the video, How can I understand using homeroute or userroute? What kind of role are routes playing when we send requests and receive responses from the server?
Thanks,
3 Answers
![Montazar Al-Jaber](https://uploads.teamtreehouse.com/production/profile-photos/5390532/micro_city4.jpg)
Montazar Al-Jaber
19,611 PointsThis is actually an example of a protocol. You, as a developer, define the protocol however you want. In this case, the teacher have decided (and by convention) that if the URL is a forward slash ('/') then the client most likely want the index.html
file. If the URL contain anything beside a forward slash, the teacher have decided that it must be a request for information about a particular user.
Do distinguish between the two requests (for index.html
and the user information), the teacher have chosen two routes: home and user. Now, anyone that want to use your services must adhere to this protocol, i.e., a simple forward slash for index.html
and a username for information about a user.
So when should you use these two routes? It is actually up to you (again) how you define the protocol. You may not even need more than one route, and instead handle it through the request body, or you may want even more routes. It is up to you, but using two different routes may be simpler. To summarize: a route can be used to easily distinguish between the kind of request (e.g., for index.html
, logging in, logging out, retrieving information about a user) to send the appropriate response.
![Piotr Manczak](https://uploads.teamtreehouse.com/production/profile-photos/10607994/micro_20200829_211123.jpg)
Piotr Manczak
Front End Web Development Techdegree Graduate 29,253 PointsSo if I type in the browser bar home address I just get general info with no user info and when I type url ending with username I get user info? This is what you are saying?
![Charles Wanjohi](https://uploads.teamtreehouse.com/production/profile-photos/8747822/micro_ngenia_20170731_123058.jpg)
Charles Wanjohi
9,235 PointsHey, having two files for Homeroute and Userroute is simply to ensure the code is neatly arranged i.e having categories for the different groups of routes based on the purpose they serve.All the routes could have been put in a single file.
To understand the different roles each of the routes play, check on the first argument passed to the app.use method in the app.js file .e.g.
app.use('/home',homeRoute);
app.use('/user',userRoute);
The above code tells express that any request sent to express with a url starting with ''/home" should be referred to the homeRoute Similarly any request with a url that starts with "/user" would be relayed to the userRoute eg a url of '/user/details' would be sent to the user route
Hope this helps you find the difference