Viewers: in countries Watching now:
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.
Find answers to the most frequently asked questions about Node.js Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
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.