title: Node wait for async function before continue
body: <p>I have a node application that use some async functions.</p>
  
  <p>How can i do for waiting the asynchronous function to complete before proceeding with the rest of the application flow?</p>
  
  <p>Below there is a simple example.</p>
  
  <pre><code>var a = 0;
  var b = 1;
  a = a + b;
  
  // this async function requires at least 30 sec
  myAsyncFunction({}, function(data, err) {
      a = 5;
  });
  
  // TODO wait for async function
  
  console.log(a); // it must be 5 and not 1
  return a;
  </code></pre>
  
  <p>In the example, the element "<code>a</code>" to return must be 5 and not 1. It is equal to 1 if the application does not wait the async function.</p>
  
  <p>Thanks</p>