NodeJS: if I return mysql data to the client at the end of the query, does this mean that callbacks do not make sense?

I am new to Node.
I need to query Mysql and return this data to the client synchronously.
If so, does it mean that I am blocking Reactor even if I use the Mysql lib? How should I do it right?

+1
source share
1 answer

I think a fake example will answer your question:

var http = require('http'); var db = require('db'); http.createServer(function (req, res) { db.query('fake query', function(data){ res.send(data); } }).listen(1337, '127.0.0.1'); 

Even if you do not send your response synchronously, that’s fine, that’s how node works. At first, I also struggled with this concept.

+3
source

Source: https://habr.com/ru/post/1433425/


All Articles