title: How to resolve a relative path in node?
body: <p>Came across this situation recently - I have an environment variable for a directory path like so:</p>
  
  <pre><code>var fooDir = process.env.FOO_DIR;
  </code></pre>
  
  <p>and I want to make sure this directory exists with a synchronous mkdir (at some point later):</p>
  
  <pre><code>fs.mkdirSync(fooDir, mode);
  </code></pre>
  
  <p>however if the user has supplied the environment variable via a realtive ~/ path node cannot resolve it</p>
  
  <pre><code>export FOO_DIR='~/foodir'
  </code></pre>
  
  <p>is there a way in node to resolve this without invoking a child process exec call to the actual shell?  currently my solution is to do a replace myself like so:</p>
  
  <pre><code>fooDir = fooDir.replace(/^~\//, process.env.HOME + '/');
  </code></pre>
  
  <p>just curious if someone has a better solution.</p>