Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,920 --> 00:00:01,940
All right, everyone.
2
00:00:02,330 --> 00:00:05,660
It's time to finally build our first node project.
3
00:00:06,990 --> 00:00:13,470
It's going to be something simple and a little silly, but it's going to get us started on our journey
4
00:00:13,770 --> 00:00:18,060
to building some really nice applications later on in the course.
5
00:00:18,750 --> 00:00:19,470
Let's start.
6
00:00:19,920 --> 00:00:24,240
So I have my hello dogs here and my terminal below.
7
00:00:24,840 --> 00:00:29,790
And we're going to start by creating a constant to save our mission.
8
00:00:31,290 --> 00:00:37,860
Which is going to be to learn and we're going to see if our mission.
9
00:00:39,000 --> 00:00:41,260
Is equal to learn.
10
00:00:41,790 --> 00:00:45,870
Then we're going to use our console that log.
11
00:00:46,890 --> 00:00:47,730
To say.
12
00:00:48,060 --> 00:00:50,940
Time to write some note code.
13
00:00:52,600 --> 00:01:01,060
And otherwise, we're going to say console.log is whatever we put for our mission.
14
00:01:01,570 --> 00:01:10,810
So we're going to use the plus operator to concatenate the mission string with our question and we're
15
00:01:10,810 --> 00:01:15,040
going to ask is mission really more fun?
16
00:01:16,700 --> 00:01:20,300
OK, so now we can run our Hello, Douglas.
17
00:01:22,010 --> 00:01:23,450
And we should see.
18
00:01:24,050 --> 00:01:27,650
It's time to write some note code because our mission is to learn.
19
00:01:27,770 --> 00:01:35,780
But we can improve our program slightly by using this Xmas script six feature called Template Strings
20
00:01:36,380 --> 00:01:42,260
and ActionScript is just the latest standard for the JavaScript programming language.
21
00:01:43,190 --> 00:01:50,510
So recent versions of JavaScript have this feature where we can use strings with this Bektic instead
22
00:01:50,510 --> 00:01:51,380
of a quote.
23
00:01:52,450 --> 00:01:57,730
And surround our string with back ticks on both sides.
24
00:01:58,420 --> 00:02:06,520
This allows us to insert variables directly using this dollar sign and brace syntax.
25
00:02:07,090 --> 00:02:13,100
This is a little cleaner than concatenating the strings every time using that plus operator.
26
00:02:13,540 --> 00:02:22,150
And it's possible because note is kept up to date with the latest versions of the V8 JavaScript engine,
27
00:02:22,450 --> 00:02:29,350
which is in turn kept up to date with the latest features in the ActionScript standard.
28
00:02:29,890 --> 00:02:36,790
What this means is that newer versions of Node will contain the latest JavaScript language features.
29
00:02:37,480 --> 00:02:44,470
This is great, but up until now, all of our code here has been just JavaScript.
30
00:02:45,190 --> 00:02:47,230
We could copy and paste it.
31
00:02:48,210 --> 00:02:52,470
And in our browser, in our developer tools.
32
00:02:54,000 --> 00:02:59,910
We could paste our code into the JavaScript console and we get the same output.
33
00:03:01,070 --> 00:03:09,380
But remember, because we're using node, we actually get a few extra benefits because it's a runtime,
34
00:03:09,800 --> 00:03:15,260
it doesn't just run JavaScript, we get a few tools on top of that.
35
00:03:15,860 --> 00:03:24,560
So just like the browser here has the window object, which we can use on the browser, and it contains
36
00:03:24,560 --> 00:03:25,520
things like.
37
00:03:26,710 --> 00:03:33,910
If we scroll through it, it has functions like the alert function to show an alert window to the user.
38
00:03:34,990 --> 00:03:38,410
It has a window that close function.
39
00:03:39,220 --> 00:03:42,700
And if we scroll down to document.
40
00:03:43,690 --> 00:03:48,880
The window object is storing what's called the document object model.
41
00:03:49,830 --> 00:03:59,910
That the browser uses to store things like the URL being browsed and the body of the HTML.
42
00:04:00,950 --> 00:04:04,280
These are all things that are not JavaScript.
43
00:04:04,790 --> 00:04:11,540
They're added by the browser to support the functionality that it needs.
44
00:04:12,260 --> 00:04:20,510
Just like we have browser functionality in the window object here on the browser node comes with its
45
00:04:20,510 --> 00:04:31,190
own API or application programming interface, which is just a set of functions and how you use them.
46
00:04:31,790 --> 00:04:42,320
These node APIs are things that are not pure JavaScript that are included in the node runtime node exclusive
47
00:04:42,320 --> 00:04:43,070
features.
48
00:04:43,940 --> 00:04:49,880
They're things that make sense in node that don't necessarily make sense to have in a browser.
49
00:04:51,410 --> 00:04:57,500
So let's take a look at an example in our node rappel by typing just the node command.
50
00:04:58,070 --> 00:05:02,060
You'll notice that we don't have access to the window object.
51
00:05:02,300 --> 00:05:03,620
Just like we discussed.
52
00:05:03,630 --> 00:05:11,780
It doesn't really make sense to have a node, but we have other features like the process object and
53
00:05:11,780 --> 00:05:14,420
a few others that we'll talk about later.
54
00:05:14,720 --> 00:05:24,140
But we can scroll through here and we see that there's a whole bunch of different information about
55
00:05:24,140 --> 00:05:30,230
the process, which is just the node program that's currently running here.
56
00:05:31,370 --> 00:05:38,690
One of the features in this node object that I want us to take a look at right now is this RV property
57
00:05:39,050 --> 00:05:46,970
that we can see contains an array, and right now it just contains the path to our node executable.
58
00:05:47,420 --> 00:05:55,280
So this will be different on your system, depending on where node has been installed and depending
59
00:05:55,280 --> 00:05:57,890
on which operating system you're running node on.
60
00:05:58,710 --> 00:06:02,070
But it always contains that path to note.
61
00:06:02,760 --> 00:06:04,190
So what's this used for?
62
00:06:04,200 --> 00:06:08,310
What's the purpose of having process thought RV?
63
00:06:09,320 --> 00:06:13,580
Which is how we access this process, that ARG fee.
64
00:06:14,440 --> 00:06:20,800
Well, let's explore this a little bit in our browser if we search for node process.
65
00:06:21,220 --> 00:06:28,090
The first result should be the Node.js documentation, which will default to whatever the latest version
66
00:06:28,090 --> 00:06:28,960
of Node is.
67
00:06:29,680 --> 00:06:36,910
And if that doesn't match the version of node that we're currently using, then we can go to this dropdown
68
00:06:36,910 --> 00:06:39,700
and select your version of Node.
69
00:06:40,740 --> 00:06:49,350
And on the left here, we have a list of all of the modules, all of the APIs that are built into node.
70
00:06:50,310 --> 00:06:51,450
There's quite a few.
71
00:06:51,480 --> 00:06:54,670
So we'll explore this a little bit more later.
72
00:06:55,110 --> 00:07:01,980
But the one we're interested in right now is the process module, and we can see that the process object
73
00:07:01,980 --> 00:07:09,240
is a global that provides information about and control over the current Node.js process.
74
00:07:09,810 --> 00:07:15,960
Now, don't worry, we're going to talk about what global means and explore some of the other globals
75
00:07:15,960 --> 00:07:17,580
in the upcoming videos.
76
00:07:18,030 --> 00:07:26,220
But right now, we want to learn about this RV array that we saw, and the node documentation tells
77
00:07:26,220 --> 00:07:31,080
us which version of node the feature was added in.
78
00:07:31,230 --> 00:07:35,850
So in this case, one of the first versions of Node that was released.
79
00:07:36,920 --> 00:07:45,200
It tells us what the function returns in this case, an array of strings and then some documentation
80
00:07:45,200 --> 00:07:54,920
for it, so we can see that RV returns an array containing the command line arguments past when the
81
00:07:54,920 --> 00:07:57,020
Node.js process was launched.
82
00:07:57,380 --> 00:08:04,790
And then it tells us that the first element will always be the path of the node process, which we already
83
00:08:04,790 --> 00:08:13,040
saw, and that the second element will be the path to the JavaScript file being executed, while the
84
00:08:13,040 --> 00:08:17,360
remaining elements will be any additional command line arguments.
85
00:08:17,900 --> 00:08:24,140
So with this RV array, we get the arguments that were passed into node.
86
00:08:25,370 --> 00:08:33,920
Back in our ED, if I exit out of the chapel and run node, hello, guess?
87
00:08:34,860 --> 00:08:43,860
Using the process module, the Hello script can get access to the arguments that were passed to it.
88
00:08:44,550 --> 00:08:45,330
Let me show you.
89
00:08:45,930 --> 00:08:52,620
So instead of hard coding mission to learn, we're going to say mission is process.
90
00:08:53,850 --> 00:08:54,930
That RV.
91
00:08:55,900 --> 00:09:01,090
And we're going to select the argument at the second index.
92
00:09:01,960 --> 00:09:03,960
Now I can do no.
93
00:09:04,000 --> 00:09:08,430
Hello dogs and pass something afterwards.
94
00:09:08,950 --> 00:09:15,850
Say the word explorer and explorer will be passed as an argument to our script.
95
00:09:17,610 --> 00:09:24,180
It will be passed in as our gravy at zero one two.
96
00:09:24,630 --> 00:09:27,690
It will be at the second index of our array.
97
00:09:28,580 --> 00:09:37,850
And now our program knows that Explore is our mission, which is not equal to learn, so we get is explore
98
00:09:37,850 --> 00:09:39,320
really more fun than learning?
99
00:09:39,950 --> 00:09:48,830
Now I could go back to the way the code was with learned, hard coded and still in explore as an argument.
100
00:09:49,830 --> 00:09:54,360
And the court will still run, Oops, I have to save my file first.
101
00:09:55,140 --> 00:10:01,830
And we can see that the code still runs, but we get our old hardcoded response.
102
00:10:03,020 --> 00:10:08,240
This is because arguments that aren't used are just ignored.
103
00:10:09,260 --> 00:10:19,430
And now, if I add back our RV and pass in, let's say learn our hello a script is telling us that it's
104
00:10:19,430 --> 00:10:26,420
time to write some nerd code RV at the second index is Learn.
105
00:10:27,750 --> 00:10:29,550
Which makes our mission learn.
106
00:10:30,630 --> 00:10:35,280
And Arkansas, that log is the first option here.
107
00:10:36,180 --> 00:10:45,210
For now, we've used the process thought RV feature to build our first little silly node application.
108
00:10:46,120 --> 00:10:48,340
But one through which we've learned a lot.
109
00:10:49,480 --> 00:10:55,750
I now know that I have this node runtime with me, with which I can run code.
110
00:10:56,850 --> 00:10:59,100
And tell my machine what to do.
111
00:11:00,950 --> 00:11:09,890
And no, it has all of these nice things that it adds for us on top of just plain JavaScript and all
112
00:11:09,890 --> 00:11:17,510
of these things that we see in the documentation, here are things that we're going to explore throughout
113
00:11:17,510 --> 00:11:21,560
the course up until we write a real life application.
114
00:11:22,010 --> 00:11:26,630
It's going to be a good one and we're just scratching the surface.
115
00:11:27,020 --> 00:11:32,420
But I hope this gets you excited because this is just the beginning.
116
00:11:32,930 --> 00:11:34,490
I'll see you in the next video.
12100
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.