1
00:00:00,480 --> 00:00:01,610
Welcome back.

2
00:00:01,620 --> 00:00:07,500
In this video we're going to write our first nude application and they use the term application extremely

3
00:00:07,500 --> 00:00:08,190
loosely.

4
00:00:08,190 --> 00:00:13,170
It's just going to be a single file with some basic javascript but I'll show you how we can interact

5
00:00:13,500 --> 00:00:15,390
with node cons..

6
00:00:15,690 --> 00:00:19,940
And we'll also see how we can run a file with node.

7
00:00:19,980 --> 00:00:21,990
So those are the two objectives here.

8
00:00:22,020 --> 00:00:25,270
The first thing that we'll talk about is the node cons..

9
00:00:25,290 --> 00:00:29,940
So we've seen the javascript Council and the browser before which we can open up and we can interact

10
00:00:29,940 --> 00:00:35,700
with we can type javascript commands in the browser can do things like alert and constant log or whatever

11
00:00:35,700 --> 00:00:36,980
debugging that we want.

12
00:00:37,140 --> 00:00:41,310
Well node has its own version of the console and it's a little bit different because it's all based

13
00:00:41,310 --> 00:00:42,300
in the command line.

14
00:00:42,360 --> 00:00:43,900
We don't get the nice browser interface.

15
00:00:43,920 --> 00:00:48,490
There's no h l tools no inspector no elements because we're on the server side.

16
00:00:48,510 --> 00:00:49,270
There is no.

17
00:00:49,270 --> 00:00:52,590
Each time there is no CSSA to actually look at and interact with.

18
00:00:52,590 --> 00:00:57,240
So the node console is just a place that we can open in our terminal with a simple command and then

19
00:00:57,240 --> 00:01:01,840
we can start typing javascript commands and they'll be executed just like they are in the browser.

20
00:01:02,010 --> 00:01:04,020
And to be honest it's really not that useful.

21
00:01:04,060 --> 00:01:06,020
You might end up opening it once or twice.

22
00:01:06,030 --> 00:01:10,320
Aside from this video but I do like to show it just so that you know it exists.

23
00:01:10,770 --> 00:01:16,230
We can open it up by typing the command node and I'm actually going to show you how I can do it on my

24
00:01:16,230 --> 00:01:21,570
computer in the terminal first just so that you understand it works exactly the same way instead of

25
00:01:21,570 --> 00:01:23,100
the browser you use in cloud 9.

26
00:01:23,250 --> 00:01:29,180
So I type node and my cursor at the prompt changes would make that a little bigger.

27
00:01:30,030 --> 00:01:34,440
You can see if we get this or karet which means I'm now inside of the JavaScript console.

28
00:01:34,500 --> 00:01:46,050
So if I type something some javascript like four plus 10 I get 14 or I can do things like hello plus

29
00:01:47,130 --> 00:01:54,290
worlds just like that where I can do full javascript I could write a function if I wanted to.

30
00:01:54,330 --> 00:01:57,600
I won't do that here but I can just interact with javascript.

31
00:01:57,600 --> 00:02:01,830
It's something called a Ruppel are EPL which stands for.

32
00:02:01,860 --> 00:02:03,420
Read evaluate.

33
00:02:03,480 --> 00:02:04,930
Print loop.

34
00:02:04,980 --> 00:02:10,140
I'm a big fan of drawing comparisons between languages and between different frameworks and technologies

35
00:02:10,140 --> 00:02:10,310
.

36
00:02:10,320 --> 00:02:14,430
I'm actually going to show you Ruby's own REPL which we will never use in this class at all.

37
00:02:14,460 --> 00:02:18,070
But I just want to demonstrate so that you can see it works exactly the same way.

38
00:02:18,310 --> 00:02:20,180
So we need to get out of here and to quit.

39
00:02:20,340 --> 00:02:28,830
I can type Control-C twice and to open up the ruby cons. I type I Arbi it stands for interactive Ruby

40
00:02:29,440 --> 00:02:36,420
and now I can type ruby code in here so I'll type a really simple line of Ruby like 40 plus 9 and I

41
00:02:36,420 --> 00:02:38,960
get 49 and that's all I want to show.

42
00:02:39,090 --> 00:02:43,890
It's a place we can write Ruby in our command line we type IRP and hit enter and we enter like this

43
00:02:43,890 --> 00:02:50,760
new place where we can't type our command line things like LS or CD because it thinks those are Ruby

44
00:02:50,820 --> 00:02:52,800
variables or methods or something.

45
00:02:52,800 --> 00:02:54,830
Same thing when we go into the node cons..

46
00:02:54,840 --> 00:03:00,110
Now I'll show you how we can go over to cloud 9 and start working in the node consul here.

47
00:03:00,270 --> 00:03:05,920
It's the exact same command we just type node and hit enter or cursor changes.

48
00:03:05,930 --> 00:03:08,420
Now I can start writing server side javascript.

49
00:03:08,610 --> 00:03:10,570
So let's do something simple again.

50
00:03:10,740 --> 00:03:18,780
Well just to constantly log a bunch of letters just like that and we get this printed out.

51
00:03:19,110 --> 00:03:23,820
An important point I want to make is that a lot of the things that you're used to in the Java Sea are

52
00:03:23,820 --> 00:03:27,110
of counsel and the browser are not available here.

53
00:03:27,150 --> 00:03:30,620
We can't do something like alert if I try and do it alert.

54
00:03:30,710 --> 00:03:33,310
Hello I get an error.

55
00:03:33,330 --> 00:03:38,060
It tells me alert is not defined and that's because alert comes with the browser.

56
00:03:38,490 --> 00:03:42,990
And even though we're in the browser here remember that we're not actually in the browser so we're typing

57
00:03:42,990 --> 00:03:48,480
code in a browser but it's being run on one of cloud nine computers somewhere else on the server side

58
00:03:48,690 --> 00:03:55,380
where there isn't a browser so it just like me going here and going into Knode and typing alert something

59
00:03:56,320 --> 00:03:58,710
that doesn't exist because I'm not in the browser.

60
00:03:58,710 --> 00:04:02,950
Same thing like the document document doesn't exist at all in code.

61
00:04:03,090 --> 00:04:04,610
That's purely on the browser side.

62
00:04:04,710 --> 00:04:09,120
So none of the Domm none of those events listeners in one of the selectors.

63
00:04:09,130 --> 00:04:12,500
The manipulation all of that is only in the browser.

64
00:04:12,690 --> 00:04:14,400
None of that exists with note.

65
00:04:14,820 --> 00:04:17,180
That's all I want to show with the node cons..

66
00:04:17,250 --> 00:04:22,880
As I mentioned we really won't be using it much but it just a nice introduction to how Knode works.

67
00:04:22,920 --> 00:04:27,090
We can just start running Javascript in the terminal.

68
00:04:27,090 --> 00:04:32,190
The next bullet here is much more important which is how we can run a file with node.

69
00:04:32,550 --> 00:04:37,350
So what I mean by saying run a file with node is that we can create a javascript file.

70
00:04:37,410 --> 00:04:42,270
Call it whatever you want and fill it with javascript code and then we can execute it in the command

71
00:04:42,270 --> 00:04:48,900
line without a browser without any HD Melosi access just executed on its own by using the inode command

72
00:04:49,200 --> 00:04:50,060
to use it.

73
00:04:50,190 --> 00:04:54,570
We just type node and then a file name just like that.

74
00:04:54,690 --> 00:04:59,880
And if we hit enter it will try and execute whatever file we provided as Javascript.

75
00:05:00,180 --> 00:05:01,800
So let me demonstrate that now.

76
00:05:02,070 --> 00:05:05,610
I'm going to in my command line make a new file.

77
00:05:05,670 --> 00:05:07,100
I'll just call it hello.

78
00:05:07,210 --> 00:05:08,730
Yes so touch.

79
00:05:08,910 --> 00:05:09,490
Hello.

80
00:05:09,540 --> 00:05:13,550
Yes and now will type LS make sure it's there.

81
00:05:13,560 --> 00:05:14,320
There it is.

82
00:05:14,490 --> 00:05:18,650
Let's open it up in our editor and let's add some simple Javascript.

83
00:05:18,870 --> 00:05:22,670
So let's do a for loop for our i equals zero.

84
00:05:22,920 --> 00:05:30,220
I less than 10 I plus plus and will just do a constant alt log.

85
00:05:30,510 --> 00:05:33,660
Hello from Hello dot.

86
00:05:33,780 --> 00:05:34,980
J S.

87
00:05:35,010 --> 00:05:40,230
Just like that and we'll save it now.

88
00:05:40,230 --> 00:05:44,790
I can use the node command to execute this file to actually run this code.

89
00:05:44,850 --> 00:05:48,900
So again I type node and the name of the file which is hello.

90
00:05:49,100 --> 00:05:50,610
Yes and that's it.

91
00:05:50,610 --> 00:05:57,120
I hit enter and it executes the file for me and it constantly logs to this council here my terminal

92
00:05:57,130 --> 00:05:57,260
.

93
00:05:57,420 --> 00:05:58,380
Hello from Hello Dutch.

94
00:05:58,440 --> 00:06:00,040
Yes ten times.

95
00:06:00,600 --> 00:06:05,580
We won't be writing code like this very much what will actually be doing is stuff like this which you've

96
00:06:05,580 --> 00:06:08,940
already seen where I run node apps.

97
00:06:09,010 --> 00:06:15,270
Yes which is my file that has my server and it actually starts the server for me and it serves it on

98
00:06:15,270 --> 00:06:21,630
port three thousand and I can go visit port three thousand now because I ran after J.S. with noter as

99
00:06:21,630 --> 00:06:23,720
Noda executed the file.

100
00:06:24,480 --> 00:06:25,460
So that's what we'll be seeing.

101
00:06:25,470 --> 00:06:26,780
Use a lot more as.

102
00:06:26,850 --> 00:06:30,640
But we can also just do this or we have a for loop and it comes to that log.

103
00:06:30,660 --> 00:06:31,720
It works the same way.

104
00:06:31,740 --> 00:06:38,550
It's just javascript code that's being run the very last thing I'll show here is another parallel between

105
00:06:38,550 --> 00:06:44,600
javascript and node and Ruby so we can also create a ruby file and execute it.

106
00:06:44,760 --> 00:06:49,450
Not with the node command but with the ruby command and I'm showing this to you again.

107
00:06:49,530 --> 00:06:52,320
Not because you're supposed to be learning Ruby at all.

108
00:06:52,320 --> 00:06:56,490
You definitely don't have to remember this but I do want you to see it so that you can draw another

109
00:06:56,490 --> 00:07:00,660
comparison between node and Ruby and other server side languages.

110
00:07:00,660 --> 00:07:05,310
This is something you can do and pretty much every server side thing which so I'll go over here and

111
00:07:05,310 --> 00:07:12,070
make a new file called Hello RB and I'll open that file up.

112
00:07:12,140 --> 00:07:16,050
RB is how we make a ruby file and I'll just do something simple.

113
00:07:16,110 --> 00:07:18,090
Hi from hello.

114
00:07:18,130 --> 00:07:20,400
RB And we won't use a loop.

115
00:07:20,400 --> 00:07:22,540
We'll just do it three times and save.

116
00:07:22,800 --> 00:07:24,260
That is what Ruby looks like.

117
00:07:24,270 --> 00:07:26,840
No semi-colons or anything we don't need parentheses.

118
00:07:27,030 --> 00:07:28,250
I'll close out if there.

119
00:07:28,530 --> 00:07:32,270
And to execute that file instead of doing Noad hello.

120
00:07:32,400 --> 00:07:35,710
Yes I run ruby.

121
00:07:35,880 --> 00:07:38,070
Hello dot RB.

122
00:07:38,310 --> 00:07:40,810
And it executes my file which is Ruby code.

123
00:07:40,890 --> 00:07:43,390
It runs it as Ruby and it prints me.

124
00:07:43,410 --> 00:07:44,780
Hi from Hello dot RB.

125
00:07:44,820 --> 00:07:46,350
Three times.

126
00:07:47,160 --> 00:07:49,320
OK so that's all I want to show here.

127
00:07:49,350 --> 00:07:50,420
There were two objectives.

128
00:07:50,460 --> 00:07:57,210
One show you the node cancel which you can open by just typing node with no argument and then run a

129
00:07:57,210 --> 00:08:04,320
file with node which you can do with node and the file name and it needs to end and Dot J.S. in the

130
00:08:04,320 --> 00:08:05,230
next lesson.

131
00:08:05,230 --> 00:08:08,350
Good to have you write some javascript on your own and execute it with node
