title: How to create a tmp dir in node without collisions
body: <p>I have a need a create a temporary "scratch" directory on-demand in node.js.  The requirements are:</p>
  
  <ul>
  <li>the dirname should be randomized (i.e. <code>/tmp/aDIge4G/</code></li>
  <li>the directory will be created within <code>/tmp</code> which may already have other randomly named directories.</li>
  <li>if the directory already exists, I should throw rather than use it and overwrite someone else's work</li>
  <li>this needs to be safe in a concurrent environment.  I can't just check if the directory exists and then create it if it doesn't because someone else may have created a directory with the same name <em>after</em> I checked.</li>
  </ul>
  
  <p>In other words, I need the answer to <a href="https://stackoverflow.com/questions/27528034/node-js-check-if-file-exists-before-creating-temp-file">this</a> question but for directories, not files.</p>
  
  <p><a href="https://stackoverflow.com/questions/793858/how-to-mkdir-only-if-a-dir-does-not-already-exist">This</a> answer says that what I want to do can be accomplished by <code>mkdir -p</code>, but Node doesn't have the <code>-p</code> flag for <code>fs.mkdir</code></p>