In my index.js file, I have confirmed that the data is successfully retrieved using console.log. However, when I attempt to display this data in my view, I encounter an error that says:
"Cannot read property 'feedUrl' of undefined.
The following is the output from console.log, showing the data fetched from the backend which includes the feedUrl attribute that I intend to showcase in my view:
[
{
_id: 5ec4580bb82c6c10a07936b6,
feedUrl: 'http://rss.cnn.com/rss/cnn_topstories.rss',
__v: 0
},
{
_id: 5ec463ef7dd1c2d7b32a74bc,
feedUrl: 'http://rss.cnn.com/rss/cnn_world.rss'
}
];
Below is the code snippet from index.js responsible for handling this route:
// Importing necessary models
let rssLink = require('./models/rssLink')
let rssItem = require('./models/rssItem')
// Setting up template engine and defining view locations
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')
// Home route
app.get('/', (req, res) => {
// Query the database for stored links
rssLink.find({}, function(err, feedlinks){
console.log(feedlinks)
if (err) {
console.log(err)
} else {
res.render('index', {
title: 'Welcome! Please register below',
feedlinks: feedlinks
})
}
})
})
And here is my Pug file containing the view:
block content
h1 #{title}
ul each val, i in feedlinks
li= val.feedUrl
Please advise on how to overcome this issue. Thank you in advance.