T
T
Torento203452021-07-26 14:41:41
MySQL
Torento20345, 2021-07-26 14:41:41

Why is data not sent from the server to the client via post?

The post request contains a query to the database

let data = pool.query("SELECT * FROM users");
res.send(data);

At the same time, in the console, for some reason, it displays a selection of all the data from the table, although the console.log on the server is not in the post, and nothing comes to the client, only emptiness.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-07-26
@Torento20345

Accessing the database in NodeJS is asynchronous and sending the result should be in callback:

pool.query("SELECT * FROM users", (err, result)=>{
    if (err) throw new Error(err.message);

    res.send(result);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question