So I'm trying to get my .ejs file to display some more information from my API code but it keeps giving me an error code.
TypeError: /home/ubuntu/workspace/sportsapp/views/results.ejs:7
5| <li><%= game["home"]["name"]%> Vs.<%=game["away"]["name"]%>
6| <ul>
>> 7| <li><%= game["broadcast"]["network"]%></li>
8| </ul>
9| </li>
10| </ul>
Cannot read property 'network' of undefined
I'm trying to get my ejs to display the game's home team name, away team name and also what network that the game is on, but I can only figure out how to display the team names for both the home and away teams.
Below is the API I am using
{
id: "6641572c-b588-4b0e-8671-e279ced1985b",
status: "scheduled",
coverage: "full",
scheduled: "2017-02-18T17:00:00+00:00",
conference_game: true,
venue: {
id: "e1276102-db24-4188-9558-f249d69526f5",
name: "William D. Mullins Center",
capacity: 9493,
address: "200 Commonwealth Ave",
city: "Amherst",
state: "MA",
zip: "1003",
country: "USA"
},
broadcast: {
network: "NBCSN",
satellite: "220"
},
home: {
name: "Massachusetts Minutemen",
alias: "MASS",
id: "88104678-e53b-43b3-82f7-efb3a11cedb9"
},
away: {
name: "Davidson Wildcats",
alias: "DAV",
id: "2920c5fa-1e86-4958-a7c4-1e97b8e201d8"
}
},
Here is my ejs file
<% data["games"].forEach(function(game){ %>
<ul>
<li><%= game["home"]["name"]%> Vs.<%=game["away"]["name"]%>
<ul>
<li><%= game["broadcast"]["network"]%></li>
</ul>
</li>
</ul>
<% }); %>
And this is my express node app with the API key removed.
var express = require("express");
var app = express();
var request = require ("request");
app.set("view engine", "ejs");
// this is getting information from the API and returning results in the ejs.
app.get("/sportsapp", function(req, res){
request("https://api.sportradar.us/ncaamb-t3/games/2017/02/18/schedule.json?api_key=", function(error, response, body){
if(!error && response.statusCode == 200){
var data = JSON.parse(body);
res.render("results", {data : data});
}
});
});
app.listen(process.env.PORT, process.env.IP, function(){
console.log("Sports App has Started");
});
I have a feeling I'm doing something wrong with the looping part of the ejs file but I'm not sure exactly where I'm screwing up. Any help would be greatly appreciated.