There is no clear indication as to where the limit between synchronous code and asynchronous code is, it depends more on the application flow. Asynchronous operations should be preferred as they allow Node.js to the main process to start processing other requests during this time.
However, simply using callbacks for each function is not a solution, as part of the code as such:
function sum(a, b, callback){ var sum = a + b; callback(sum); } sum(2,3, function(sum){ console.log(sum); }
Still in sync. To make it asynchronous to process.nextTick , you can use as such:
function sum(a, b, callback){ var sum = a + b; process.nextTick(function(){ callback(sum); }); } sum(2,3, function(sum){ console.log(sum); }
The general rule is to avoid synchronous recursive computations, heavy loops, and I / O.
Searching if a request takes too much time and thus will hinder performance cannot be determined so that, as a rule, restrictions are application specific. These queries are located by running performance tests in the application.
source share