Isaac Alejandro
Isaac Alejandro

Reputation: 247

How can I retrieve the data object using SQL package on Node.JS?

I have a mysql query executed from NodeJS using mysql npm package.

Upon success, I want to read the value in Javascript.

Both are on the same domain.

On console.log the value I read is 3.

How can I retrieve the data object values?

var mysql      = require('mysql');
var connection = mysql.createConnection(connectionOptions);

connection.query(
  "SELECT * FROM pruebas.Usuarios2 where RFC = '123'", 
  (err, result, fields) => { 
     if (result.length) { 
       // here I need an instruction that can send me the result of 3
       // to my javascript console
     } else { 
       console.log('no login');
     }
   }
 );

Upvotes: 0

Views: 101

Answers (1)

Nelson Teixeira
Nelson Teixeira

Reputation: 6572

You don't send from Node to Javascript. You call Node from Javascript using an Ajax call and return a value.

The answer to this question is a good exemple of how to do it: Basic Ajax send/receive with node.js

Upvotes: 1

Related Questions