Check out a free preview of the full The Hard Parts of Servers & Node.js course

The "Executing Node Code" Lesson is part of the full, The Hard Parts of Servers & Node.js course featured in this preview video. Here's what you'd learn in this lesson:

Will discusses how Node is able to talk with the inner features of the server computer to enable network communication.

Preview
Close

Transcript from the "Executing Node Code" Lesson

[00:00:00]
>> Will Sentance: Let's now see JavaScript with other talent. Built-in enables a trigger node features. Because what are we trying to do, people? Our dream is about right JavaScript code that can look at an incoming message off the Internet, introspective, look into it see what it's asking for, and then send back the right tweets.

[00:00:18]
That's our dream. So there'd better be a label from in here, the axises or set up a nodes C++ feature that can access the networking feature of our computer. There better be one. What is it? Well, actually the main one's called net. But there's a more specialized one called HTTP.

[00:00:40]
The node feature that's gonna access the network card effectively and be able to receive messages in the HTTP format. And we're gonna see HTTP more detail, but for now just know it's a format by which you send messages or requests from a web browser. And whenever you type in a URL and press ENTER, you send out a message.

[00:01:09]
And it's sent out automatically in the HTTP format, Hypertext Transfer Protocol. Protocol means format of data and rules by how you communicate. The format of data, HT, hypertext, that's the structure of webpages linked between them, transfer, that means transfer. Good. And we need to have our network open, we're gonna discover we open a socket which is an open connection to the Internet, an open channel to the internet, two-way open channel to the Internet.

[00:01:44]
We're gonna discover that open connection, we need to have it formatted such that it's ready to receive HTTP formatted messages. How are we gonna do that from JavaScript? Via what, Roman?
>> Roman: With CSS.
>> Will Sentance: Not with CSS, so-
>> Roman: I mean with C++.
>> Will Sentance: With C++, exactly. Most probably in node featurable HTTP, and its associated built-in label in JavaScript, and guess just want me by label.

[00:02:11]
It's a label a word in here that will trigger something down here. It's called HTTP. Okay, here we go, people. Using HTTP feature of node to set up an open socket connection to the Internet. Socket's a posh word for open channel for data to go in and out of a place over the Internet.

[00:02:31]
People, what do I wanna build? I wanna build a cool looking app. If we get this principle down, there's nothing else to note. Today, we're gonna see all features of node, besides two, we may have tied to the modularity. You may have time, and we have time to do handling multiple threaded tasks in some way handling multiple jobs or incident instances as a one thing we're going to touch.

[00:03:02]
But otherwise this model we're gonna see will apply to every single node feature that you ever encounter. All right, here we go, using the HTTP feature of node to open a socket to the Internet such that when an inbound message comes in from the web, we can run code in JavaScript to send back a message to Sarah Rose's Mac.

[00:03:26]
Let's see how we use our built in label up here. And I will say this, people, immediately just so you're not confused. This built-in label is gonna be HTTP.create server. It's a label for a node C++ feature that says we're open channel to the Internet. That label is not automatically available to us in JavaScript.

[00:03:46]
We're gonna see a little bit later on, how do we tell JavaScript that we want to have access to that background mood feature. One line will bring that labeling. It's not dissimilar though to in the browser if you remember things like set time out, which is unlabeled in JavaScript, there's no timer in JavaScript, so there's a label in JavaScript for a feature in the web browser, but set time out is built in automatically.

[00:04:13]
It's very similar, this is not quite built in automatically we have to announce we want it, but it's effectively almost built-in automatically. We'll see announcing we want, it will be later on. For now let's just use it. Let's use it, let's use it, let's use it, let's use it.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now