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 Handling Routes in Node.js Populating User Information

tal Shnitzer
PLUS
tal Shnitzer
Courses Plus Student 5,242 Points

who is making the request from the server we have created?

who is making the request from the server? we have created a server that is getting a request and answer with a response. the reponse is shown on treehouse port 3000. but I don't understand: at this stage - who is making the request? how the request is being issued?

5 Answers

andren
andren
28,558 Points

You, or more accurately your browser (Chrome, Firefox, Safari, etc) is the one making the request by the very act of visiting the URL.

When you tell your browser to connect to a page it uses a protocol called HTTP to send a GET request to the server which asks it to send back data. Once the server receives the request, it looks at what page was requested and runs code to fetch and prepare the data needed to display the page. Then it sends a response back to your browser, which your browser then renders for you.

That explanation is a bit simplified since I don't want to get too technical, but it should give you a general understanding. And Treehouse does have some courses centered on this topic, specifically How the Internet Works, How the Web Works and the workshop HTTP: Do you GET it?.

tal Shnitzer
PLUS
tal Shnitzer
Courses Plus Student 5,242 Points

thanks. so when I've clicked on the workspace right corner "eye" button, I've actually asked to get treehouse on port 3000?

andren
andren
28,558 Points

Yes, the URL Treehouse generates forwards your request to port 3000 on your current workspace.

tal Shnitzer
PLUS
tal Shnitzer
Courses Plus Student 5,242 Points

thanks. would you happen to also know by any chance what will happen when I'll run it from my own computer, not using the workspaces? I've installed the node.js and run command line app through terminal. there was no need for a browser. who will generated the URL and the request when I'll run it locally? even while I ask this question it sounds to me like the browser should do it, but how?

andren
andren
28,558 Points

If you ran the project from this course on a locally installed version of Node.js it would start a web server on your local machine.

There would be no domain name pointing at the server but domain names (like teamtreehouse.com) are actually just labels for IP Addresses, which is what computers on the internet actually use to connect to each other. So it's not actually needed to connect to a server, as you can connect to it directly using its IP Address.

Specifically you can connect to it by going to the following URL in your browser: http://127.0.0.1:3000

That address (127.0.0.1) is a special address that always points to the machine it is used on, and the :3000 part is how you tell your browser what port to connect to.

Web development with Node.js is usually done using a framework called Express, the syntax for that is a bit different from what is shown in this video, but that also starts a web server on your machine which you can connect to in the same way as shown above.

I have done a decent amount of programming in Node.js and Express, so if you have any further questions about those or anything else brought up in this post then feel free to ask them.

tal Shnitzer
PLUS
tal Shnitzer
Courses Plus Student 5,242 Points

great, thanks. I might have after trying to run it locally ,when I'll finish this course. You've beed a great help

andren
andren
28,558 Points

That's good to hear :smile:.