Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
So, here's my solution to the challenge. I've already installed all the dependencies and I've started the application on port 3000. So, I'm going to go to port 3000 in my browser and then the /list/json route. Now, all the flight information is being displayed as JSON. So let's take a look at how I did this. I'm going to drag the final folder into sublime text two and then I'm going to go to routes slash index dot js. At the very bottom of this file, I created a new function called list json.
Then on line 42, I started a new blank array called flight data On line 44, I started a loop and iterated over all the flights. Then one by one I got the information from each flight object and pushed it into the array. Then, finally on line 48, I sent a res.json response back with the flight data. Then in app.js I attached the list json function to the route /list /json. Now one approach you may have taken while solving this challenge.
So I'm going to stop the server and I'm going to start it again. I'm going to press the up arrow on my keyboard, to get node app.js and I'm going to run it. And now, I'm going to pull up /list/json again. I'm just going to refresh the browser here. So this still displays correctly, but there's a problem with the data. And that's that the property names here are numbers. In JSON, you can't use numbers as the property names. So this is not valid JSON. By using the loop here, we're able to get the flight data and put it into an array.
Since we already have the flight numbers as a part of the data, we're not losing any information. So that's how you can deliver all of the flight data as valid JSON.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99874 Viewers
56 Video lessons · 112990 Viewers
71 Video lessons · 81827 Viewers
131 Video lessons · 39263 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.