title: Synchronize node.js object
body: <p>I am using a variable and that is used by many functions at a time. I need to synchronize it. How do I do it?</p>
  
  <pre><code>var x = 0;
  
  var a = function(){
    x=x+1;
  }
  
  var b = function(){
    x=x+2;
  }
  
  var c = function(){
    var t = x;
    return t;
  }
  </code></pre>
  
  <p>This is the simplified logic of my code. To give more insight, X is as good as my mongoDB object which needs to be used by only one function at a time. Also 3 functions are like REST api calls so there is probability they will be called at same time. </p>
  
  <p>I need to write getX function which should manage locking and unlocking.</p>
  
  <p>Any suggestions?</p>