I wrote the code below to read values ββfrom mongodb using mongoose and store it in an array:
app.get('/StudentQuestionsPage',function(req,res){
var allQuestionsArray = studentQuestions.find();
var questions = [];
allQuestionsArray.exec(function(err,questions){
if(err)
return cosole.log(err);
questions.forEach(function(question){
var elem = new Object();
elem["id"] = question.id;
elem["quesStatement"] = question.quesStatement;
elem["optionA"]=question.optionA;
elem["optionB"]=question.optionB;
elem["optionC"]=question.optionC;
elem["optionD"]=question.optionD;
questions.push(elem);
console.log(elem)
});
});
res.render(__dirname + '/StudentQuestionsPage.html',{questions:questions});
});
I need to pass this array of questions to an html file, and then I have to show the content in HTML.
I wrote below code to display array values ββin HTML, but it shows nothing. " console.log(elem)" can print values ββto the console.
<html>
<head>
<title>Online Examination Portal</title>
<h1>Questions</h1>
</head>
<body>
<div>
<form>
<h2>Questions</h2>
<ul>
<% questions.forEach(function(question) { %>
<li>Number: <%= question.id %> <br/> Text: <%= question.quesStatement %></li>
<% }); %>
</ul>
</form>
</div>
</body>
</html>
Please let me know how I can pass values ββfrom nodejs and extract them and show them in html.
source
share