The Hard Parts of Servers & Node.js Local Node Development
Transcript from the "Local Node Development" Lesson
>> Will Sentance: The problem is though, but if ever I wanna test, is my code working right, do I need to load up to Amazon's computer? Wait for it to load up, okay, we're good to go and open the website now. Michael, do you mind just opening twitter.com and checking my website is working?
[00:00:15] Did I get the right request? I handled it, no, I sent back the wrong one. Hold on, Michael, can you just stay there and open it again in three minutes? Now, we definitely don't have to do that. So we want to do it all on our computer. Both the being Michael sending a message to the computer that's got the open connection to the Internet ready to listen for your messages, running node.
>> Will Sentance: Let's see if that's possible, have a look at this.
[00:00:57] So I'm on my computer, they call this my development machine. It's my computer which I'm developing. Here's what I do.
>> Will Sentance: I load up,
>> Will Sentance: Internals, there it is, okay.
>> Will Sentance: I set up the open channel to the Internet, right, the open channel to the Internet at port, well open channel to the Internet socket. Now in theory, if I wanted to run and test whether I was waiting messages correctly and ready to send them back correctly I'd need a totally separate, Michael you need to send a message to my computer, right, to see if I get a message in and send something back.
[00:01:55] That would be ridiculous. I'd have to do that. I'd have to sit calling Michael to send messages to my computer the whole time, to see if something is coming in.
>> Will Sentance: So the designers of operating systems realized this was ridiculous. So they invented a feature, I'm sorry. They invented a feature that allows us to open our web browser on the same computer we're running, our node app, open our web browser.
[00:02:24] Open not through the .com, but a special domain name called local host.
>> Will Sentance: And then put, I don't know, tweet three or whatever. And it's gonna send out a message, not to the Internet. But it's a special domain name that loops straight back in to our own computer where we were listening.
[00:02:53] It loops it straight back in. By the way, local host has a domain especially an IP address 127.0.0.1. And this allows us people to write code to set up our server to open the socket on our computer. But to have the ability to access our own computer by not having to go to another computer, open twitter.com that sends a message to our computer.
[00:03:22] But do it from our own computer with a special built into our operating system domain name, local host that loops us right back into our own computer. That sends the sends the outbound HTTP message not out into the Internet, but straight back to our own computer. And we have a special IP address that references from inside our own computer.
[00:03:43] References our own computer, it's 127.0.0.1, which has a domain name so you don't have to remember it, local host. Here's a problem, we tend not to want to use the port 80, that's the entry point 80 that's used default for the browser going out. Instead, we want to use any one of the numbers of the 64,000 entry points we can use.
>> Michael: 80.
>> Will Sentance: 80 but if we're not gonna be entering at that point into our own computer we better declare when we send out with the help of a colon the exact port that we're gonna send out that we expect it to come in at. And we put it in there.
[00:04:37] And that means, we can send out a little HTTP message, which never really even leaves our computer. By the way, in the old days, before this was built into your operating system, they used to literally take a wire out the back of the computer, and loop it back into the machine.
[00:04:52] But now it's part of the operating system so the message doesn't even leave the computer. It comes straight back in and enters. And that's gonna allow you people to both write your code for your server to listen and receive messages and send stuff back. But also test it's working by opening the domain name that accesses your own computer directly.
[00:05:34] .And set the right port. And then we get to access our own computer's open channel using that domain name. And that's what we're gonna do in the pair programming. Okay, I think it's what I said here. What about testing our server? Do you need to load the code to be run on AWS to test it live?
[00:05:52] No, operating system developers, that's the people who built this whole computer, included the loop back feature, with local host as a pseudo domain. A pretend domain name that sends out your message not out to the Internet, but straight back into your own computer. This is what we'll be doing in the pair programming.