- [Instructor] In this video, we'll create an endpoint
that serves all of our messages.
We no longer need this test endpoint,
so we'll modify line five to get what we want.
The first thing we'll modify is the location.
So instead of slash for root,
we'll specify slash messages.
Then instead of simply sending a response
got send with test string, we'll get rid of that,
and we'll put in a new block.
Then we'll go to our front end project in our other editor,
I'll scroll down, and I'll grab
line 17 that has our messages.
I'll copy that, and I'll create a new constant
called messages, and I'll set that
to the messages we copied.
Then I'll use a response.send and I'll pass in the messages.
So I'll save that, and rerun node.
So I'll shut it down with control C and start it up again.
But instead of doing that, we can use node mon
and specify our server.
Node mon is a command line tool
that automatically scans for
any saved changes and restarts node.
I currently don't have it,
so the first thing we'll need to do is install it.
So I'll use npm install slash G for global,
since it's a command line tool, and specify node mon.
And then I'll try that again.
Node mon server dot JS.
So now anytime I make a change,
I don't have to manually restart node.
I'll just hit save, and we can see it restarts.
And if we just refresh this, we can see it cannot get root.
That's because we got rid of that root endpoint
and instead we have slash messages.
And we can see our messages.
So we now have an endpoint that serves our messages,
which our front end can now talk with.
One final note I'd like to make
is that in a production environment,
instead of using a hard coded messages array,
we'd of course be using a database.
But since the focus of this course is front end
and back end working together to create an app,
we won't be spending much time
on how to manage and save data
using a solution like MongoDB, for example.
We'll just be using an in-memory solution,
such as an array.
So once again, now that we have that all set up,
it's time to request this data from our front end.
Let's go ahead and set that up in the next video.