title: Node.js asynchronous function, process.nextTick()
body: <p>I'm writing a node backend and I'm a little confused how should I deal with async functions. I've read about process.nextTick(), but how often should I use. Most of my code is based on callbacks, like database calls, which are asynchronous by themselves. But I also have a few functions of my own, that should be async.</p>
  
  <p>So which one is a good example of async function?</p>
  
  <pre><code>function validateUser1(user, callback) {
  
    process.nextTick(function() {    
  
       //validate user, some regex and stuff
  
       callback(err, user);
  
    });
  
  }
  
  function validateUser2(user, callback) {
  
    //validate user, some regex and stuff
  
    process.nextTick(callback, err, user);
  
  }
  
  function validateUser3(user, callback) {
  
    process.nextTick(function() {    
  
      //validate user, some regex and stuff
  
      process.nextTick(callback, err, user);
  
    });
  
  }
  </code></pre>
  
  <p>I don't know whether I should wrap everything in process.nextTick , or wrap just the callback? or both? </p>
  
  <p>And overall, the idea with node.js is to write lots of small functions rather than bigger ones, and call them asynchronously to not block other events, right?</p>