I working on a code to printing some user info on a webpage using node.js and express-hbs
I tried this code
<!DOCTYPE html>
<html>
<head>
<title>Person List</title>
</head>
<body>
<table>
{{#each person}}
<tr>
<td>{{person.id}}
</td>
<td><a href='/person/'+person.id>{{person.firstname}}</a></td>
<td>{{person.GameId}}</td>
</tr>
{{/each}}
</table>
<td>{{person.firstname}}</td>
</body>
</html>
node.js code
app.get('/usersrooms', function (req, res, next) {
var personList = [];
//var userslist = "SELECT * FROM users ORDER BY id";
connection.query('SELECT * FROM users ORDER BY id', function(err, rows, fields) {
if (err) {
res.status(500).json({"status_code": 500,"status_message": "internal server error"});
} else {
// Loop check on each row
for (var i = 0; i < rows.length; i++) {
// Create an object to save current row's data
var person = {
'email':rows[i].email,
'firstname':rows[i].firstname,
'GameId':rows[i].GameId,
'id':rows[i].id
}
// Add object into array
personList.push(person);
}
res.render('index', {"personList": personList});
}
});
// Close the MySQL connection
connection.end();
});
but I get this error when I run it and the server disconnect and I don't get any data on my webpage
throw er; // Unhandled 'error' event ^
Error: Cannot enqueue Quit after invoking quit.