Jetzt bin ich verwirrt. counter ist definiert in getBuildingInformationForEach(), müsste also in app.get('/count_buildings', ...); doch existieren? Die Console.log() innerhalb app.get('/count_buildings', ...); werden aus irgendeinem Grund nicht ausgeführt.
function getBuildingInformationForEach(){
var counter;
console.log("1. type: " + typeof(counter));
app.get('/count_buildings', function(req, res) {
console.log("type: " + typeof(counter));
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : ''
});
connection.connect();
connection.query('sqlQuery', function(err, results) {
if (err) throw err;
counter ={buildingsCounter:results};
console.log("2. type: " + typeof(counter));
res.json(counter);
});
connection.end();
});
lupus(0, 1, function(n) {
console.log("3. type: " + typeof(counter));
app.get('/Buildings_Details-'+n, function(req, res) {
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : ''
});
connection.connect();
connection.query('sqlQuery', function(err, rows, fields) {
if (err) throw err;
res.json({Wohnungen:rows});
});
connection.end();
});
},
function() {
console.log('All done!');
});
};
getBuildingInformationForEach();
Das sagt die Konsole, wenn ich den Server starte.
- type: undefined
Example app listening on port 8080!
- type: undefined
All done
Gruß Uri