M
M
myspace2017-03-05 19:03:01
Node.js
myspace, 2017-03-05 19:03:01

In nodejs, when working with a database, does all logic need to be stored within a callback?

For example, we get from mysql which field

connection.connect();
   
  connection.query('SELECT * from `etc`', function(err, rows, fields) {
    if (err) throw err;
    console.log('Телефон: ', rows[0].phone);
  });

  connection.end();

it turns out that all manipulations with the received data must be done within the second argument of the connection.query method?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2017-03-05
@myspace

yes, it's asynchronous vermicelli and the benefits of non-blocking code. If you don’t like this option, everything that needs to be processed in callbacks should be wrapped in promises and use async await constructs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question