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)
![Leo Marco Corpuz](https://secure.gravatar.com/avatar/41a122ae992ae47a0555e219474391fe?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Leo Marco Corpuz
18,975 PointsUser route
I still don't understand why we're replacing the "/" with an empty string for the user route. Isn't the "/" part of the request? (i.e. "/chalkers")
2 Answers
![Neil McPartlin](https://secure.gravatar.com/avatar/28c97e648f2f03d369da419a0365bdcb?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Neil McPartlin
14,662 PointsHi Leo. Let's just focus on what Andrew has done in the first 2 minutes of this video. His code up to that point, just for the userRoute, is as shown below...
//Handle HTTP route GET /:username i.e. /chalkers
function userRoute(request, response) {
//if URL == '/...'
var username = request.url.replace('/', '');
if(username.length > 0) {
//get JSON from treehouse
//on 'end'
//show profile
//on 'error'
//show error
}
}
We are writing code for a website but think of it as 2 locations. What a user 'requests' on their browser (local computer), and how our server 'responds' to their request. A user has submitted a request for badge information for 'leomarcocorpuz'. This action results in a GET request being sent to our server using 'https://teamtreehouse.com/leomarcocorpuz'.
We currently have 2 routes defined in the app.js file. There is a '/' detected in the GET request so the userRoute will be the one that determines what response gets sent back to the user.
The first thing we need to isolate is the username, so everything after the domain name including the '/' gets extracted i.e. /leomarcocorpuz. Finally, in order to extract the actual username, we need to effectively remove the '/' by replacing it with ' ' (i.e. nothing).
So long story short, we are not 'creating' a URL, we are simply 'reading' a URL in order to decide what information to send back to the user.
![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 why wouldn't we use url/username.slice() method to get just the username? If we replace '/' with empty string we will get "url username" instead of username only.
Greg Wienecke
126 PointsGreg Wienecke
126 PointsThanks Neil