1
00:00:00,590 --> 00:00:10,730
Less initialize our projects as NPM because we want to use third party packages like Express Mongoose

2
00:00:10,730 --> 00:00:12,110
and many more.

3
00:00:12,320 --> 00:00:19,640
So for this I'm going to use the built in terminal that came with Visual Studio Code and you can use

4
00:00:19,640 --> 00:00:21,320
any terminal of your choice.

5
00:00:21,320 --> 00:00:24,670
So I'm going to open that by clicking on terminal.

6
00:00:24,680 --> 00:00:26,540
And here we go.

7
00:00:26,930 --> 00:00:35,060
The first command is called NPM init and for this I can give it a flag for yes.

8
00:00:35,150 --> 00:00:41,390
And this one going to give me the default configuration and I can override them.

9
00:00:41,390 --> 00:00:48,260
So let's hit enter and you can see that this had the configuration that it has given to me.

10
00:00:48,590 --> 00:00:57,110
The first property is called name, and it took the name of the folder that I use, the version of my

11
00:00:57,110 --> 00:01:04,760
project, the description, and then the main file it used the server to file because that is what I

12
00:01:04,790 --> 00:01:06,050
created here.

13
00:01:06,440 --> 00:01:09,980
And then the next property is called the script.

14
00:01:09,980 --> 00:01:18,940
So let's open the package JSON file and you can see that we have additional file called package the

15
00:01:18,980 --> 00:01:20,150
JSON file.

16
00:01:20,150 --> 00:01:24,380
And this is the same as I was showing you in the terminal.

17
00:01:24,470 --> 00:01:29,990
So for the description, I can give this one as Foo stock.

18
00:01:31,660 --> 00:01:33,460
Blog application.

19
00:01:34,140 --> 00:01:41,400
And then the main for this one, if your file is up and you couldn't pick it up, you can change this

20
00:01:41,400 --> 00:01:48,990
one to server or app or index, but make sure that it's used the same name as your file.

21
00:01:48,990 --> 00:01:56,070
And then this one going to be the script and this one going to contain the script for running our application.

22
00:01:56,070 --> 00:02:01,620
And even in deployment, it's going to use a script here to start our server.

23
00:02:02,070 --> 00:02:11,190
And for key words, if we want to improve the process, we can put your keywords here as block and then

24
00:02:11,190 --> 00:02:15,690
comma, I would say Node.js and many more.

25
00:02:15,810 --> 00:02:23,760
And then the author for this project, I'm going to use my school name as I never take academic.

26
00:02:24,090 --> 00:02:28,260
And then four Line says, I would like to use this one.

27
00:02:28,350 --> 00:02:32,190
All right, so this is a package JSON file.

28
00:02:32,190 --> 00:02:40,020
So what is it where, as the name implies, it's going to use to manage the packages for our application.

29
00:02:40,260 --> 00:02:45,210
The next step is that let's install the packages that we may need.

30
00:02:45,210 --> 00:02:47,200
So back to the terminal.

31
00:02:48,110 --> 00:02:50,730
And I'm going to install these packages.

32
00:02:50,750 --> 00:02:57,910
So for now, I would like to install Xpress and Mongoose for now.

33
00:02:57,990 --> 00:02:59,480
I'm going to hit enter.

34
00:03:00,970 --> 00:03:01,660
All right.

35
00:03:01,660 --> 00:03:04,450
These two packages have finished in Sterling.

36
00:03:04,450 --> 00:03:08,200
So let's go ahead and start to create our server.

37
00:03:08,230 --> 00:03:14,350
So first step is I'm going to require the express package as that.

38
00:03:14,350 --> 00:03:18,340
And for this, we are going to use common way.

39
00:03:18,670 --> 00:03:27,460
The next step is that I'm going to initiate the instance of the Express as AB is equal to express.

40
00:03:27,670 --> 00:03:35,200
So this line of code simply means that I am calling the function given to us by experts and assigned

41
00:03:35,200 --> 00:03:37,180
to a variable called AB.

42
00:03:37,480 --> 00:03:45,580
So for this, if I console log AB, I'm going to have all the properties that has given to us by experts.

43
00:03:45,610 --> 00:03:53,110
Let me open the terminal again and to run this file we are going to use Node and then the name of the

44
00:03:53,110 --> 00:04:02,860
file, which server dot G is going to be our server dot G s and you can see all the methods and functions

45
00:04:02,860 --> 00:04:08,050
and properties given to us by Express to make our life easier.

46
00:04:08,140 --> 00:04:14,830
So on the app, we have couple of methods, for example, to be able to create a server.

47
00:04:14,980 --> 00:04:20,920
So let's have some comment here and then we're going to fill them up as we move on.

48
00:04:31,630 --> 00:04:36,940
So for the meantime, we are going to work on the listening to server.

49
00:04:36,970 --> 00:04:41,170
So the first one is I need to create what is called port.

50
00:04:41,170 --> 00:04:46,660
And this simply means what number is our application is going to listen to.

51
00:04:46,750 --> 00:04:53,170
And for this we are going to use what is called process dot, EMV, dot port.

52
00:04:53,170 --> 00:04:59,860
And then if there is no value on the port, then we are going to use 9000.

53
00:05:00,070 --> 00:05:03,460
The next step is that we are going to listen to the server.

54
00:05:03,460 --> 00:05:10,750
So on the app we have a method called Listen and in here our pass in the port, then this one going

55
00:05:10,750 --> 00:05:18,310
to be the callback function is going to be as console log and I will say that server.

56
00:05:19,820 --> 00:05:21,170
Is running.

57
00:05:26,350 --> 00:05:30,040
On parts and I'm going to inject the port.

58
00:05:30,040 --> 00:05:35,680
So let me use backtrack here and backtrack also here and here.

59
00:05:35,740 --> 00:05:39,850
Going to be a dollar sign carry basis and then the port.

60
00:05:40,300 --> 00:05:45,700
The next step is that I need to configure the script to run the application.

61
00:05:45,700 --> 00:05:51,280
And you can see here that we have additional properties being added called dependencies.

62
00:05:51,280 --> 00:05:55,660
For now we are using two dependencies for our application.

63
00:05:55,660 --> 00:06:01,660
So we inside the script, we are going to maintain this one because you may need this one if you deploy

64
00:06:01,660 --> 00:06:09,160
your application and going to use this keyword core start and use node to start our server, but we

65
00:06:09,160 --> 00:06:12,550
don't want to restart our server any time we make changes.

66
00:06:12,550 --> 00:06:20,380
Because of that, we are going to install a third party package for Node one and this is going to help

67
00:06:20,380 --> 00:06:23,680
us to restart the application automatically.

68
00:06:23,680 --> 00:06:26,670
Any time we make changes, we're going to be empty.

69
00:06:26,680 --> 00:06:28,540
Am I?

70
00:06:28,540 --> 00:06:35,800
And then the name going to be Node one and I'm going to install this one as dev dependencies and I'm

71
00:06:35,800 --> 00:06:37,360
going to give it to DE.

72
00:06:37,870 --> 00:06:44,770
Now no one has finished installing, so let me close this one and inside here I'm going to use what

73
00:06:44,770 --> 00:06:46,180
is called server.

74
00:06:47,260 --> 00:06:48,680
The name is up to you.

75
00:06:48,700 --> 00:06:51,260
You can name it whatever you want by here.

76
00:06:51,280 --> 00:06:53,680
I want to pass in two agreements.

77
00:06:53,710 --> 00:06:55,810
The first one is called Not.

78
00:06:56,320 --> 00:07:01,150
And then the file that you want to run, which is server towards cheese.

79
00:07:01,750 --> 00:07:05,320
So next step is that let's run the application.

80
00:07:05,320 --> 00:07:10,750
So let's open a terminal by making use of NP run server.

81
00:07:12,400 --> 00:07:17,360
And you can see that my server is listening on Port 9000.

82
00:07:17,380 --> 00:07:26,320
Before we end this video, you can see that I have two files called package that log dot JSON and then

83
00:07:26,320 --> 00:07:28,690
the package JSON file.

84
00:07:28,720 --> 00:07:35,620
I have this to file because I'm using two package managers and that is John and NPM.

85
00:07:35,620 --> 00:07:37,420
So I'm going to remove this one.

86
00:07:38,150 --> 00:07:43,160
Because an application needs only one package JSON file.

87
00:07:43,190 --> 00:07:49,160
Now that we have our server up and running in this video, let's go ahead and connect application to

88
00:07:49,160 --> 00:07:50,210
MongoDB.

