title: How to lock (Mutex) in NodeJS?
body: <p>There are external resources (accessing available inventories through an API) that can only be accessed one thread at a time.</p>
  
  <p>My problems are:</p>
  
  <ol>
  <li>NodeJS server handles requests concurrently, we might have multiple requests at the same time trying to reserve inventories.</li>
  <li>If I hit the inventory API concurrently, then it will return duplicate available inventories</li>
  <li>Therefore, I need to make sure that I am hitting the inventory API one thread at a time</li>
  <li>There is no way for me to change the inventory API (legacy), therefore I must find a way to synchronize my nodejs server.</li>
  </ol>
  
  <p>Note: </p>
  
  <ul>
  <li>There is only one nodejs server, running one process, so I only need to synchronize the requests within that server</li>
  <li>Low traffic server running on express.js</li>
  </ul>