Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,690 --> 00:00:01,400
All right guys.
2
00:00:01,410 --> 00:00:03,930
So how did that go?
3
00:00:04,340 --> 00:00:09,990
So, the first thing we're going to do is we're going to delete any projects that are open inside Atom and
4
00:00:10,020 --> 00:00:16,860
open up a brand new Hyper Terminal that is at our home location, which is represented by the little tilde
5
00:00:16,860 --> 00:00:17,890
squiggly line.
6
00:00:18,180 --> 00:00:23,460
So now that we've got everything clear and ready to go, the first thing we're going to do is we're going
7
00:00:23,460 --> 00:00:30,390
to cd into our desktop, or cd to any location you wish, and we're going to create our new directory, that's
8
00:00:30,390 --> 00:00:32,509
going to be called Calculator.
9
00:00:33,090 --> 00:00:37,800
So now that we've got our Calculator directory, we're going to cd to it,
10
00:00:37,800 --> 00:00:44,460
and inside here we're going to create a new file called calculator.js.
11
00:00:44,700 --> 00:00:50,940
So now that we've got our file and our directory ready to go, we're going to initialize NPM with npm
12
00:00:51,030 --> 00:00:57,100
init. And the name is going to be called calculator, version, description,
13
00:01:02,230 --> 00:01:04,050
entry point is going to be at calculator.js,
14
00:01:04,060 --> 00:01:09,450
author is myself,
15
00:01:09,600 --> 00:01:12,680
and we're going to hit enter to create that.
16
00:01:12,690 --> 00:01:18,180
All right. So now that we've created it, we're going to open this project inside Atom with
17
00:01:18,290 --> 00:01:19,030
atom .
18
00:01:19,170 --> 00:01:24,880
And now we're going to install Express with npm install express.
19
00:01:25,170 --> 00:01:29,930
So this is the workflow that you’re going to be going through every single time you create a new web site,
20
00:01:29,940 --> 00:01:34,370
so it's really good to just get it into your bones and get familiar with it.
21
00:01:34,380 --> 00:01:42,110
So in our package.json, we now have a single dependency that is express, and we can now go into our calculator.js
22
00:01:42,130 --> 00:01:45,510
and we can require it.
23
00:01:45,510 --> 00:01:48,580
So we're going to create a new const called express.
24
00:01:48,690 --> 00:01:51,960
This is going to be set to require express,
25
00:01:55,420 --> 00:02:05,280
and I'm going to add that comment up here, jshint esversion:6.
26
00:02:05,450 --> 00:02:14,770
So now that we've got our const express, then we're going to set up a new app that is going to be using
27
00:02:14,800 --> 00:02:16,610
the express module.
28
00:02:16,900 --> 00:02:23,990
And finally I wanted you to create a home route, so that's going to be app.get.
29
00:02:24,100 --> 00:02:25,950
We're going to target the home route.
30
00:02:26,170 --> 00:02:32,080
And then we're going to have a callback function with a request and a response, and we're simply going
31
00:02:32,080 --> 00:02:38,170
to respond by sending, “Hello world!”
32
00:02:38,200 --> 00:02:44,890
So now that we've defined our route, then we're going to spin up our server, and we do that with app.listen,
33
00:02:44,920 --> 00:02:51,250
and we're going to listen again on port 3000, and then we're going to have a callback
34
00:02:51,520 --> 00:02:59,120
that simply logs that the server is running on port 3000.
35
00:02:59,820 --> 00:03:00,180
All right.
36
00:03:00,220 --> 00:03:07,500
So now that we've set up our home route, we've got our app to listen on port 3000.
37
00:03:07,510 --> 00:03:13,630
Now you can choose any other port, by the way. You can choose 4040, 8080, 5000, whatever you
38
00:03:13,630 --> 00:03:14,650
wish.
39
00:03:14,830 --> 00:03:21,030
And you can head over there with localhost comma whatever port you chose to see it.
40
00:03:21,160 --> 00:03:25,420
But 3000 is the most commonly used port when people are developing locally,
41
00:03:25,420 --> 00:03:27,910
so that's what we're going to be using as well.
42
00:03:27,910 --> 00:03:32,190
So we're now pretty much ready to run and spin up our server.
43
00:03:32,200 --> 00:03:38,970
So let's head over to the command line, making sure that we're inside the project that contains our calculator.js.
44
00:03:39,010 --> 00:03:42,760
We’re going to use Nodemon to spin up our
45
00:03:42,770 --> 00:03:43,610
calculator.js.
46
00:03:43,610 --> 00:03:51,730
And if at any point during the code writing process you have made a mistake, then you can see that,
47
00:03:51,730 --> 00:03:58,720
just as we had errors logging in the Chrome Developer Tool Console, our command line will also show us
48
00:03:58,870 --> 00:03:59,930
any errors.
49
00:04:00,100 --> 00:04:06,190
And in this case it's telling me that expres with a single s is not defined. And this is one of the
50
00:04:06,190 --> 00:04:13,480
most common thing that happens when you misspell, or you make a typo, or you forget to make a particular
51
00:04:13,480 --> 00:04:19,140
word capitalized when it should be, then it will say something something is not defined.
52
00:04:19,149 --> 00:04:23,800
This just means that it doesn't know what you're talking about. It doesn't know what expres with a single
53
00:04:23,800 --> 00:04:25,060
s is.
54
00:04:25,120 --> 00:04:32,090
And it also point to you to the line of your code where this occurs, and that is on calculator.js
55
00:04:32,110 --> 00:04:39,660
line number 5, and the little arrow points to the specific thing that is offending it.
56
00:04:39,670 --> 00:04:46,000
So let's head over to our calculator.js file line number five, and we can see that we've forgotten
57
00:04:46,090 --> 00:04:47,450
an s here.
58
00:04:47,710 --> 00:04:51,800
So now let's save and we've corrected that.
59
00:04:51,910 --> 00:04:59,230
And Nodemon automatically restarts our server with the changes, and it's now all green, and we get a log
60
00:04:59,290 --> 00:05:03,480
statement saying, “Server is running on port 3000.”
61
00:05:03,490 --> 00:05:06,150
So let's head over to
62
00:05:06,210 --> 00:05:07,520
localhost:3000.
63
00:05:07,620 --> 00:05:11,690
And there it is. Our server is running on port 3000,
64
00:05:11,700 --> 00:05:15,860
our home route is working, and we're using Express to do all of that.
65
00:05:16,060 --> 00:05:21,990
So that was a quick recap of everything that we've done so far in the form of a challenge.
66
00:05:22,180 --> 00:05:28,240
I hope it was all right for you guys, and you didn't make typos like I did, and you figured out how to
67
00:05:28,240 --> 00:05:29,990
debug your web site
68
00:05:30,010 --> 00:05:33,130
based on the messages you get in the console.
69
00:05:33,130 --> 00:05:40,190
So in the next lesson, we're going to be creating some HTML forms which we will add to our web site.
70
00:05:40,210 --> 00:05:42,970
So for all of that and more, I'll see you on the next lesson.
7215
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.