From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Create and test a GET endpoint

Create and test a GET endpoint

- Okay, so far we have a working node server with an endpoint that simply sends back hello when we hit it. The next thing we're going to do is make our server do something a little more useful. What we're going to do is create a /people endpoint that we can hit that'll send us back a JSON object with people data in it. This would be really useful, for example, if we had a front end that needed to load people data when the user visited the site. So in a full scale production server, we definitely want to use an actual database such as MongoDB or SQL or something like that to store our data. But what we're going to do for now is simply hard code our data just for the sake of example. So inside our source folder, let's create a new file and we'll call it people.js and hit enter. And what we're going to do in here is define an array of people data that we can have our server send back to the client when it hits the /people endpoint. So that'll look like this. We're going to say, let…

Contents