From the course: Learning Node.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create a get messages service

Create a get messages service - Node.js Tutorial

From the course: Learning Node.js

Start my 1-month free trial

Create a get messages service

- [Instructor] Let's begin by creating a getMessages service endpoint, and note, this will allow us to get actual messages from our backend to our front-end website. Inside our server.js, let's add a route for our endpoint. We will be using app.get to specify that we will be handling GET requests. So between line four and five, let's add a few lines, so that we can make room for app.get. Then for the first parameter, we need to specify the route. We'll use /messages, since we'll be supplying a list of messages. And then we'll need our callback to handle the request. That will take in request, and then give us reference to response, so that we can respond to it. For now, let's respond with a test string that says hello. So we'll use response dot send and then a string that says hello. We can try this out in our browser by navigating to the endpoint with a /messages. And then we can see the string hello. Next, let's create a placeholder messages list as an array at the top. We will call…

Contents