As shown below, I want to render a template for each topic in an array (this will have 50ish topics. Within the template, I need a variable set to the topic name when the user navigates to that path so that I can use that variable value to query a DB to render the correct items on the page. Right now, I'm just trying to log that variable, but it's not logging.
topics.forEach((topic) => {
app.get(
'/' + topic,
function (req, res, next) {
res.render('template', {
topic: 'welcome to ' + topic,
});
next();
},
function (req, res) {
currentTopic = topic;
console.log(currentTopic);
}
);
});