Less initialize our projects as NPM because we want to use third party packages like Express Mongoose
and many more.
So for this I'm going to use the built in terminal that came with Visual Studio Code and you can use
any terminal of your choice.
So I'm going to open that by clicking on terminal.
And here we go.
The first command is called NPM init and for this I can give it a flag for yes.
And this one going to give me the default configuration and I can override them.
So let's hit enter and you can see that this had the configuration that it has given to me.
The first property is called name, and it took the name of the folder that I use, the version of my
project, the description, and then the main file it used the server to file because that is what I
created here.
And then the next property is called the script.
So let's open the package JSON file and you can see that we have additional file called package the
JSON file.
And this is the same as I was showing you in the terminal.
So for the description, I can give this one as Foo stock.
Blog application.
And then the main for this one, if your file is up and you couldn't pick it up, you can change this
one to server or app or index, but make sure that it's used the same name as your file.
And then this one going to be the script and this one going to contain the script for running our application.
And even in deployment, it's going to use a script here to start our server.
And for key words, if we want to improve the process, we can put your keywords here as block and then
comma, I would say Node.js and many more.
And then the author for this project, I'm going to use my school name as I never take academic.
And then four Line says, I would like to use this one.
All right, so this is a package JSON file.
So what is it where, as the name implies, it's going to use to manage the packages for our application.
The next step is that let's install the packages that we may need.
So back to the terminal.
And I'm going to install these packages.
So for now, I would like to install Xpress and Mongoose for now.
I'm going to hit enter.
All right.
These two packages have finished in Sterling.
So let's go ahead and start to create our server.
So first step is I'm going to require the express package as that.
And for this, we are going to use common way.
The next step is that I'm going to initiate the instance of the Express as AB is equal to express.
So this line of code simply means that I am calling the function given to us by experts and assigned
to a variable called AB.
So for this, if I console log AB, I'm going to have all the properties that has given to us by experts.
Let me open the terminal again and to run this file we are going to use Node and then the name of the
file, which server dot G is going to be our server dot G s and you can see all the methods and functions
and properties given to us by Express to make our life easier.
So on the app, we have couple of methods, for example, to be able to create a server.
So let's have some comment here and then we're going to fill them up as we move on.
So for the meantime, we are going to work on the listening to server.
So the first one is I need to create what is called port.
And this simply means what number is our application is going to listen to.
And for this we are going to use what is called process dot, EMV, dot port.
And then if there is no value on the port, then we are going to use 9000.
The next step is that we are going to listen to the server.
So on the app we have a method called Listen and in here our pass in the port, then this one going
to be the callback function is going to be as console log and I will say that server.
Is running.
On parts and I'm going to inject the port.
So let me use backtrack here and backtrack also here and here.
Going to be a dollar sign carry basis and then the port.
The next step is that I need to configure the script to run the application.
And you can see here that we have additional properties being added called dependencies.
For now we are using two dependencies for our application.
So we inside the script, we are going to maintain this one because you may need this one if you deploy
your application and going to use this keyword core start and use node to start our server, but we
don't want to restart our server any time we make changes.
Because of that, we are going to install a third party package for Node one and this is going to help
us to restart the application automatically.
Any time we make changes, we're going to be empty.
Am I?
And then the name going to be Node one and I'm going to install this one as dev dependencies and I'm
going to give it to DE.
Now no one has finished installing, so let me close this one and inside here I'm going to use what
is called server.
The name is up to you.
You can name it whatever you want by here.
I want to pass in two agreements.
The first one is called Not.
And then the file that you want to run, which is server towards cheese.
So next step is that let's run the application.
So let's open a terminal by making use of NP run server.
And you can see that my server is listening on Port 9000.
Before we end this video, you can see that I have two files called package that log dot JSON and then
the package JSON file.
I have this to file because I'm using two package managers and that is John and NPM.
So I'm going to remove this one.
Because an application needs only one package JSON file.
Now that we have our server up and running in this video, let's go ahead and connect application to
MongoDB.