Can anyone knows how can I pass MySQL result to a JSON object using NodeJS?
// my code
var mysql = require('mysql');
var records = {};
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: ''
});
connection.query('USE MyDB');
function getRecords() {
connection.query("select * from records where id = ?", id, function(err, result) {
if (err) {
return done(err);
}
records = result;
return records;
});
}
From these code, I want to use the return records in other operations in my project. Can anyone help me to pass MySQL result to JSON object so I can use the data outside the function?
Thank you.