rn3w rn3w - 1 year ago 45
Node.js Question

i have a function mysql in nodejs and can't parsear the result

My function is:

objBD.query('SELECT MAX(ID_U) FROM usuario', function(err, rows, fields) {
console.log(rows);
});


The result is


RowDataPacket<'MAX':43>


I need the max number, example: 43

Answer Source

The rows variable returned by mysql's callback is an array, even if the result is only one row (as in the case of using max). To access the result you should access the first row of the array, as in:

console.log(rows[0])

It will likely give an output of: {'MAX': 43}