0

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');
     }
   }
 );
Dimitri Kopriwa
  • 13,139
  • 27
  • 98
  • 204
Isaac Alejandro
  • 247
  • 1
  • 3
  • 8
  • Have you read https://www.npmjs.com/package/mysql#performing-queries ? You can try to add `console.log(JSON.stringify({ results, fields }));` within `if (result.length) { }` block – Dimitri Kopriwa Dec 21 '18 at 19:58
  • How are you calling this? From where? Is this running on some sort of server? Think we need some more explanation. – putvande Dec 21 '18 at 20:45

1 Answers1

1

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

Nelson Teixeira
  • 6,297
  • 5
  • 36
  • 73