title: node.js: How to lock/synchronize a block of code?
body: <p>Let's take the simple code snippet: </p>
  
  <pre><code>var express = require('express');
  var app = express();
  var counter = 0;
  
  app.get('/', function (req, res) {
     // LOCK
     counter++;
     // UNLOCK
     res.send('hello world')
  })
  </code></pre>
  
  <p>Let's say that <code>app.get(...)</code> is called a huge number of times, and as you can understand I don't want the line <code>counter++</code> to be executed concurrently by the two different threads.</p>
  
  <p>Therefore, I want to lock this line that only one thread can have access to this line. My question is how to do it in node.js? </p>
  
  <p>I know there is a lock package: <code>https://www.npmjs.com/package/locks</code>, but I'm wondering whether there is a "<em>native</em>" way of doing it without an external library. </p>