I am loading data from the database using mysql drivers for node.js. https://github.com/felixge/node-mysql
I want to load data into the array. When I am loading data into the array - there is a delay and the array is empty.
I want to retrieve data and then write the lines - console.log("END QUERY"); console.log(users);
var users = [];
client.query(
'SELECT * FROM users',
function selectCb(err, results, fields) {
if (err) {
throw err;
}
if (results.length > 0) {
var reader = results[0];
console.log("ID: " + reader['id']); //ADD string - 'ID: 1'
users = [reader['id']]
}
}
);
console.log("END QUERY");
console.log(users);
OUTPUT:
WRITE LINE:
END QUERY
[]
ID: 1