I am new to node js. Now I am trying to set the select query return value in mysql using node js .... I am using the node -mysql package ...
code example
var mysql = require('mysql'); var connection = mysql.createConnection({ host : "localhost", user : "root", password: "root123", database: "testdb" }); var retValue = undefined; var query = connection.query('SELECT * FROM tblData;'); query .on('error', function(err) { // Handle error, an 'end' event will be emitted after this as well }) .on('fields', function(fields) { // the field packets for the rows to follow }) .on('result', function(row) { // Pausing the connnection is useful if your processing involves I/O connection.pause(); processRow(row, function() { retValue = row; }); }) .on('end', function(row) { }); connection.end(); function processRow(rows) { retValue = rows; } console.log(retValue);
retValue always undefined. I know this is an asynchronous call. will someone tell me how to set the value for this variable.
Thanks Deepak
source share