[MUSIC]
>> Hi there. I'm Christopher Harrison,
Senior Program Manager inside of Microsoft Cloud and AI.
In this section what I want to do is introduce Express.
For those of you that are not familiar,
Express is a package library
that will allow you to, relatively quickly,
stand up our rest and API endpoints,
and even go ahead and create
a fully functional server-side based web application.
Now what we're going to see here is how we can go
ahead and get it set up and get it configured.
Admittedly, some of this is going to be relatively boilerplate.
So you might find yourself in the future using
a generator to go ahead and put a lot of this code together.
Now because of the fact that this is a Node package,
we've gone ahead and registered it
inside of our package.json file.
Now we went ahead and grabbed two other little helpers as well.
One which is the body parser,
which is going to help us manage
the information that's going to be sent up to the API,
that we're going to be building; cores,
which will allow us to control where requests
can come from, and then nodemon,
which is a little helper function or helper package,
that will allow us to automatically restart
our application every time that we make a change.
It's great for development.
You can see it actually in action down there at the bottom.
Now let's go ahead and start creating our server.
We start off basically every
single Express app that will ever create,
even the most complex ones,
by creating an instance of the Express object here,
that we'll typically call app.
Now we'll be able to configure app.
So for starters, we're going to specify a port.
You're going to notice that,
we're going to try to read this from
the environmental variables and if we can't find it there,
we'll set a default of 5,000,
which is traditionally the default for local development here.
We'll tell it to listen on that port number and
then we'll set up a little event handler for when it starts,
just to say server up.
What you're going to notice when we save this is,
we'll then get that server up.
Now we can use this app, again,
to go ahead and configure how we want things to operate.
Like I mentioned before,
a lot of this is going to be boilerplate.
So let's configure two main items here.
We're going to configure cores
and once I can spell request correctly,
we're going to configure the body parser.
Let's start with the body parser.
What the body parser is going to do is,
it's going to help us read the information
that the user has sent up to the server,
or the client has sent up to the server.
We're going to configure everything for
managing URL encoded data and then what we're
going to do is tell it that
the body needs to be converted into JSON.
Now again, all of this is really boilerplate.
What's great about this is,
it's going to make it easier for us to work
with the data that's going to be sent up to our application,
which we'll see in later videos.
The other big thing that we want to
configure is this little thing known as cores,
and what cores will do is
basically give us control over where requests
are allowed to come from when they're being sent via a browser.
That by default, you're only allowed, through a browser,
to be able to access APIs that are
on the server from which the page was rendered.
By using cores, we can say, "Hey,
this could come from somewhere else."
That allows us to have one site that's going to be
spitting out the client and then the
other that's going to be managing the server.
There's our configuration and in the next section,
we're going to see how we can start to use this.