- Up until now we've been using placeholder message data
located on the frontend, in this video,
we'll take a look at how to set up our back end
to serve our messages, to do that, we'll be using
express js, we'll first begin by creating the new folder
beside our frontend, called back end.
So using the editor, I'll go over to file,
new window, and that will create a new editor environment
for us, then I'll go over to file, open folder,
and I'll right click beside our frontend,
and select new folder, and I'll call it backend.
Then I'll select that folder, now let's
initialize the project, I'll go over to terminal,
select new terminal, and I'll type in mpm init dash y,
I'm using dash y in order to select all the defaults
automatically, and that will create our package.json file.
The next thing we'll need to do is install express js,
so I'll use mpm install express -- save,
and that will install express and save
it in our dependencies list in our package.json file.
The next thing I'll do is create a new file
and this is where all of our server code will exist,
so I'll type in server.js,
now let's set up express, so I'll use const
and create a constant named express
and set it to require and specify express.
Then I'll create out app constant called app,
and set it to a new object created by the express function.
Then I'll create a constant for our port
and set that to three thousand.
Now let's create a test route we can use
to see if our express setup is working.,
so I'll use app.get and I'll be using the slash
for the root location, then I'll pass in
an inline function that takes a request and response,
and then I'll send some placeholder data,
that simply says test, then let's instruct our app
to listen on the port we specified,
so I'll use app.listen, I'll pass in the port constant
and then another inline function
that gives us some feedback in the case
that our app is listening successfully,
so I use a console.log ...
And I'll console log app running,
and that's it, now we use node
and specify our server file and hit enter.
We can see our app running console log,
and let's this out, so let's go to our browser,
we'll go to local host port three thousand
and specify the root location,
and we can see we're getting test so it's working,
so we've set up express to work with a test service
running on the root location, the next thing we'll need
to do is create and endpoint that serves all
of our messages, let's take a look
at how to do that next.