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

The "JavaScript Node Development" 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 describes how to write code in JavaScript, load the code into Node, and then run the code. Nodemon is introduced as well.

Preview
Close

Transcript from the "JavaScript Node Development" Lesson

[00:00:00]
>> Will Sentance: Let's so quickly now talk. Though not quickly as it's really important. How the hell do we get JavaScript started to do all this? In the web browser, when I write code in the web browser, I open an HTML file in there. I have some JavaScript code in there.

[00:00:12]
And the browser just runs it. Turns on. When as soon as you open a web page in the browser, it turns on JavaScript and starts running through JavaScript code. Beautiful. We don't have that. We don't have that here. So here's how we do it. Let's see over here.

[00:00:28]
I'm for now gonna get rid of Michael's Mac, if you don't mind. Okay over here.
>> Will Sentance: This is Will's Mac.
>> Will Sentance: Well actually hold on. Ignore that, ignore that, ignore that. We are building for Twitter's computer. We're building for Twitter's computer. I need to, in Twitter's computer, turn on node to run JavaScript code.

[00:01:04]
Where can I write JavaScript code? Anywhere, I can write it on a napkin and copy it in. Is that a word in America? Yeah exactly. I can write on a napkin and copy it in. I don't know what words you have in America. I don't. I write on a piece of paper, as what like what Harry Potter was written originally on.

[00:01:20]
I could write on that, a beautiful code, and copy it in. Or in a text editor on Vasco whatever. So in VS code I guess that CBS code this be both popular. I will start writing JavaScript code like what is it? Server, account server, HTTP dot and so forth.

[00:01:39]
I'll then save that as a file. Maybe I call it server.js. It doesn't matter. I would it server.js, whatever I want. .js is a text file but by the way it's actually got JavaScript code in it. But it's just a text file. Now, I now need to turn on, this is an app.

[00:01:58]
Note it's an app that I turn on like a web browser. Web browser's an app that has access to computers internal features. The web browser as well, right, because it's sending out messages to the Internet through the computer internal features. Knows no different. How do I open a normal app on my computer like the web browser?

[00:02:12]
Double click. Exactly. Unfortunately, node isn't like that. I can't double click node, because developers hate double clicking. They are pathologically oppose for using that mice, their mouse. What it mice? No, I call things. These are mouse, what's a mice? They are pathologically opposing using the mouses. So, instead they have a different way of interfacing with the computer's features of using apps, turning on apps and its Google terminal.

[00:02:43]
You've seen it before, probably the terminal command line. I'm sure many of you seen it. And we can turn stuff on from it, we can run Spotify songs on here, by our Spotify, kind of cool. But we can also turn on node by writing node and pressing enter.

[00:02:59]
When we do so, we want to have it start running some JavaScript code. Where do we tell it to run the code from? Well, we could write code from here. It will start running. Turn on JavaScript, start running JavaScript code, turn on node features using JavaScript code. But we're not.

[00:03:13]
We're gonna save that code in a file and just put the name of it here. Server.js. Node server.js, William?
>> William: Yes, sir?
>> Will Sentance: Sir, honored. Wait a sec, we'll go to Andrews, I'm watching Andrews eyes be distracted by the laptop, all right.
>> Andrew: Sorry.
>> Will Sentance: No, of course not don't worry at all.

[00:03:32]
>> Andrew: I was seeing if I had node installed already.
>> Will Sentance: That is an important question. So you right node if it's installed, it will start loading. It will turn on node ot it will turn on the java engine that will allow you to turn on node features by writing java script code.

[00:03:44]
We write all that java script code in the file, save it as server.js or whatever you want to save it as. Look at this I learned how to, yeah. Yeah, thank you. [LAUGH] Never was a more sarcastic hand Ray, Clark raised by Matt all right. There it is.

[00:04:01]
Save it load, okay. Write the code in the VS code or whatever. Load into node and run it. How to load and using the terminal interface. Load it in. This is gonna load this in to start running. Here's the problem. We need to reload our code with node, the code of jobs.

[00:04:18]
If we change anything do our jobs code, we have to turn off node. Turn it back on. Run through the jobs code and settle all those features all over again. Because I know you could say that someone raises more than, hold on, can you selectively turn node back on.

[00:04:34]
You selectively edit stuff down here that we know is gonna have break changes and live features. Now you just switch of the whole server, the whole of the node and you just turned it back on again. To do so, we use a slightly different variant of node which is gonna store, is optional on the challenges.

[00:04:50]
We run slightly different variant if we want to have it automatically every time we change jobs or code and save it that that code. As soon as we save it, the node app will turn off and turn back on and run through the draft code all again, all over again setting up the node features and do it automatically every time we make any changes to JavaScript by using nodemon.

[00:05:13]
It's just a slightly different version of node that was a pack is a wrapper around node. That when it, well I just say, I mean JavaScript change happens, it will turn off node, turn it back on again, run through the JavaScript code, set up all the features again to make sure your changes are applied down here.

[00:05:30]
Okay, that's using nodemon.

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