Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!