I'm having trouble calculating the "transfer" variables (I know this is not the right term, I will explain), given the asynchronous nature of node.js.
Please take a look at the following:
connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) { if(err) { throw err; } var solution = rows[0].solution; }); res.render('index', { title: solution });
As you can imagine, I get a reference error, solution is not defined . This is because res.render is executed before a solution is received from the mysql server.
How can I render a page after defining a solution? I know this is really small and stupid and really located in the very heart of the node, but please help me understand.
user1130217
source share