Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
Node.JS - Query returns an empty array at first, then, after a few tries, it returns the expected result

So, I need a little help regarding a node.js code that I'm trying (more like failing) to write.

It's a simple code, I'm sure, but coming from a C#, .NET background, I still don't understand that much of js, so things can be tricky.

This is my code, currently:

var mysql = require('mysql');
var resultQuery = [];

con.connect(function(err) {
    if (err) throw err;
    con.query(myQuery, function (err, result, fields) {
      if (err) throw err;
      resultQuery = result;
    });
  });

 export default function tarefas(request, response){
      const taskList = [];

      response.json({
          taskList: resultQuery 
    })
  }

And as the first response I'll get, it's going to be something like this

Then, if I keep hitting F5, eventually it will bring my list as expected, but I still wasn't able to determine why it doesn't bring the result right away.

Can anybody help me out with this?

Thank you sincerely.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda