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

174
Views
Javascript | Can't get value from pool.query to outside function

I tried to connect with database and get a data to operate but it's gone struck on "pool.query" it can't return value back to outside. I tried a many way to solve but it's can't. So please help me to solve it. Thank you very much for your time.

This is my code Connect to database site:

const mysql = require('mysql');
const express = require('express');

const pool = mysql.createPool({
    connectionLimit: 100, //important
    host: 'localhost',
    user: 'root',
    password: 'Edcrfvtgb',
    database: 'employeesystem',
    debug: false
});

The issue is "It can't return value out from function", T^T

let selectQuery = 'SELECT * FROM ?? ';
let query = mysql.format(selectQuery, ["employee"]);


let dataQuery = '';



const getData = pool.query(query, (err, data) => {


    if (err) throw err;

    dataQuery = JSON.stringify(data);
    dataQuery = JSON.parse(dataQuery);
    console.log(dataQuery[1].name);/*Check value and typeof is object*/ 

});

console.log(dataQuery); /*no value in here*/

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!